From e90803a21e3f50d453540553f73bf5f25389e033 Mon Sep 17 00:00:00 2001 From: Jordi Olivares Provencio Date: Fri, 17 May 2024 16:48:32 +0000 Subject: [PATCH] Add benchmark and modify code --- .../wiredtiger/wiredtiger_record_store_bm.cpp | 121 +++++++++++++++++- .../wiredtiger/lang/python/wiredtiger.i | 4 +- .../wiredtiger/src/cursor/cur_backup.c | 1 + .../wiredtiger/src/cursor/cur_config.c | 1 + .../wiredtiger/src/cursor/cur_ds.c | 1 + .../wiredtiger/src/cursor/cur_dump.c | 1 + .../wiredtiger/src/cursor/cur_file.c | 1 + .../wiredtiger/src/cursor/cur_hs.c | 1 + .../wiredtiger/src/cursor/cur_index.c | 1 + .../wiredtiger/src/cursor/cur_join.c | 6 +- .../wiredtiger/src/cursor/cur_log.c | 1 + .../wiredtiger/src/cursor/cur_metadata.c | 1 + .../wiredtiger/src/cursor/cur_stat.c | 41 +++--- .../wiredtiger/src/cursor/cur_table.c | 2 + .../wiredtiger/src/cursor/cur_version.c | 1 + .../wiredtiger/src/include/cursor.h | 46 +++---- .../wiredtiger/src/include/packing_inline.h | 24 +++- .../wiredtiger/src/include/wiredtiger.in | 4 +- .../wiredtiger/src/lsm/lsm_cursor.c | 1 + .../wiredtiger/src/packing/pack_api.c | 5 +- 20 files changed, 207 insertions(+), 57 deletions(-) diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_bm.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_bm.cpp index 1ec07c5f999..c6720631b7b 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_bm.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_bm.cpp @@ -27,10 +27,129 @@ * it in the license file. */ - +#include +#include namespace mongo { namespace { +void BM_BaseWTset_key(benchmark::State& state) { + WT_CONNECTION* conn; + int ret = wiredtiger_open("", nullptr, "in_memory=true,log=(enabled=false)", &conn); + (void)ret; + WT_SESSION* sess; + ret = conn->open_session(conn, nullptr, "", &sess); + WT_CURSOR* c; + ret = sess->create(sess, "table:mytable", "key_format=q,value_format=q"); + ret = sess->open_cursor(sess, "table:mytable", nullptr, nullptr, &c); + int64_t value = state.range(); + for (auto _ : state) { + c->set_key(c, value); + } + c->reset(c); + ret = sess->close(sess, nullptr); + ret = conn->close(conn, nullptr); +} + +void BM_BaseWTget_key(benchmark::State& state) { + WT_CONNECTION* conn; + int ret = wiredtiger_open("", nullptr, "in_memory=true,log=(enabled=false)", &conn); + (void)ret; + WT_SESSION* sess; + ret = conn->open_session(conn, nullptr, "", &sess); + WT_CURSOR* c; + ret = sess->create(sess, "table:mytable", "key_format=q,value_format=q"); + ret = sess->open_cursor(sess, "table:mytable", nullptr, nullptr, &c); + int64_t value = state.range(); + c->set_key(c, value); + for (auto _ : state) { + int64_t result; + c->get_key(c, &result); + } + c->reset(c); + ret = sess->close(sess, nullptr); + ret = conn->close(conn, nullptr); +} + +void BM_RawWTset_key(benchmark::State& state) { + WT_CONNECTION* conn; + int ret = wiredtiger_open("", nullptr, "in_memory=true,log=(enabled=false)", &conn); + (void)ret; + WT_SESSION* sess; + ret = conn->open_session(conn, nullptr, "", &sess); + WT_CURSOR* c; + ret = sess->create(sess, "table:mytable", "key_format=q,value_format=q"); + ret = sess->open_cursor(sess, "table:mytable", nullptr, "raw", &c); + int64_t value = state.range(); + for (auto _ : state) { + std::array storage; + WT_ITEM item; + item.data = storage.data(); + wiredtiger_struct_pack(sess, storage.data(), storage.size(), &item.size, "q", value); + + c->set_key(c, &item); + } + c->reset(c); + ret = sess->close(sess, nullptr); + ret = conn->close(conn, nullptr); +} + +void BM_RawWTget_key(benchmark::State& state) { + WT_CONNECTION* conn; + int ret = wiredtiger_open("", nullptr, "in_memory=true,log=(enabled=false)", &conn); + (void)ret; + WT_SESSION* sess; + ret = conn->open_session(conn, nullptr, "", &sess); + WT_CURSOR* c; + ret = sess->create(sess, "table:mytable", "key_format=q,value_format=q"); + ret = sess->open_cursor(sess, "table:mytable", nullptr, "raw", &c); + int64_t value = state.range(); + + std::array storage; + WT_ITEM item; + item.data = storage.data(); + wiredtiger_struct_pack(sess, storage.data(), storage.size(), &item.size, "q", value); + + c->set_key(c, &item); + + for (auto _ : state) { + WT_ITEM get; + c->get_key(c, &get); + int64_t result; + wiredtiger_struct_unpack(sess, item.data, item.size, "q", &result); + } + c->reset(c); + ret = sess->close(sess, nullptr); + ret = conn->close(conn, nullptr); +} + +void BM_HybridWTset_key(benchmark::State& state) { + WT_CONNECTION* conn; + int ret = wiredtiger_open("", nullptr, "in_memory=true,log=(enabled=false)", &conn); + (void)ret; + WT_SESSION* sess; + ret = conn->open_session(conn, nullptr, "", &sess); + WT_CURSOR* c; + ret = sess->create(sess, "table:mytable", "key_format=q,value_format=q"); + ret = sess->open_cursor(sess, "table:mytable", nullptr, nullptr, &c); + int64_t value = state.range(); + for (auto _ : state) { + std::array storage; + WT_ITEM item; + item.data = storage.data(); + wiredtiger_struct_pack(sess, storage.data(), storage.size(), &item.size, "q", value); + + c->set_raw_key(c, &item); + } + c->reset(c); + ret = sess->close(sess, nullptr); + ret = conn->close(conn, nullptr); +} + +BENCHMARK(BM_BaseWTset_key)->Ranges({{{1}, {10'000'000}}}); +BENCHMARK(BM_RawWTset_key)->Ranges({{{1}, {10'000'000}}}); +BENCHMARK(BM_BaseWTget_key)->Ranges({{{1}, {10'000'000}}}); +BENCHMARK(BM_RawWTget_key)->Ranges({{{1}, {10'000'000}}}); +BENCHMARK(BM_HybridWTset_key)->Ranges({{{1}, {10'000'000}}}); // No WT-specific record store benchmarks for now. } // namespace diff --git a/src/third_party/wiredtiger/lang/python/wiredtiger.i b/src/third_party/wiredtiger/lang/python/wiredtiger.i index 1a4f8a269f1..a1c82aa7e24 100644 --- a/src/third_party/wiredtiger/lang/python/wiredtiger.i +++ b/src/third_party/wiredtiger/lang/python/wiredtiger.i @@ -736,12 +736,12 @@ typedef int int_void; int_void _set_recno(uint64_t recno) { WT_ITEM k; uint8_t recno_buf[20]; - size_t size; + size_t size, used_bytes; int ret; if ((ret = wiredtiger_struct_size($self->session, &size, "r", recno)) != 0 || (ret = wiredtiger_struct_pack($self->session, - recno_buf, sizeof (recno_buf), "r", recno)) != 0) + recno_buf, sizeof (recno_buf), &used_bytes,"r", recno)) != 0) return (ret); k.data = recno_buf; diff --git a/src/third_party/wiredtiger/src/cursor/cur_backup.c b/src/third_party/wiredtiger/src/cursor/cur_backup.c index ce856a3762d..e9160d6f262 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_backup.c +++ b/src/third_party/wiredtiger/src/cursor/cur_backup.c @@ -314,6 +314,7 @@ __wt_curbackup_open(WT_SESSION_IMPL *session, const char *uri, WT_CURSOR *other, __wt_cursor_get_value_notsup, /* get-value */ __wt_cursor_get_raw_key_value_notsup, /* get-raw-key-value */ __wt_cursor_set_key_notsup, /* set-key */ + __wt_cursor_set_raw_key, /* set-key */ __wt_cursor_set_value_notsup, /* set-value */ __wt_cursor_compare_notsup, /* compare */ __wt_cursor_equals_notsup, /* equals */ diff --git a/src/third_party/wiredtiger/src/cursor/cur_config.c b/src/third_party/wiredtiger/src/cursor/cur_config.c index bd44991ad1b..1e0e1bddab3 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_config.c +++ b/src/third_party/wiredtiger/src/cursor/cur_config.c @@ -38,6 +38,7 @@ __wt_curconfig_open( __wt_cursor_get_value, /* get-value */ __wt_cursor_get_raw_key_value, /* get-raw-key-value */ __wt_cursor_set_key, /* set-key */ + __wt_cursor_set_raw_key, /* set-key */ __wt_cursor_set_value, /* set-value */ __wt_cursor_compare_notsup, /* compare */ __wt_cursor_equals_notsup, /* equals */ diff --git a/src/third_party/wiredtiger/src/cursor/cur_ds.c b/src/third_party/wiredtiger/src/cursor/cur_ds.c index dc879be04db..6b76ae3ca7e 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_ds.c +++ b/src/third_party/wiredtiger/src/cursor/cur_ds.c @@ -434,6 +434,7 @@ __wt_curds_open(WT_SESSION_IMPL *session, const char *uri, WT_CURSOR *owner, con __wt_cursor_get_value, /* get-value */ __wt_cursor_get_raw_key_value, /* get-raw-key-value */ __wt_cursor_set_key, /* set-key */ + __wt_cursor_set_raw_key, /* set-key */ __wt_cursor_set_value, /* set-value */ __curds_compare, /* compare */ __wt_cursor_equals, /* equals */ diff --git a/src/third_party/wiredtiger/src/cursor/cur_dump.c b/src/third_party/wiredtiger/src/cursor/cur_dump.c index 31127a7a513..3e920733696 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_dump.c +++ b/src/third_party/wiredtiger/src/cursor/cur_dump.c @@ -396,6 +396,7 @@ __wt_curdump_create(WT_CURSOR *child, WT_CURSOR *owner, WT_CURSOR **cursorp) __curdump_get_value, /* get-value */ __wt_cursor_get_raw_key_value_notsup, /* get-raw-key-value */ __curdump_set_key, /* set-key */ + __wt_cursor_set_raw_key, /* set-key */ __curdump_set_value, /* set-value */ __wt_cursor_compare_notsup, /* compare */ __wt_cursor_equals_notsup, /* equals */ diff --git a/src/third_party/wiredtiger/src/cursor/cur_file.c b/src/third_party/wiredtiger/src/cursor/cur_file.c index 00b96170316..628ad65dfe5 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_file.c +++ b/src/third_party/wiredtiger/src/cursor/cur_file.c @@ -949,6 +949,7 @@ __curfile_create(WT_SESSION_IMPL *session, WT_CURSOR *owner, const char *cfg[], __wt_cursor_get_value, /* get-value */ __wt_cursor_get_raw_key_value, /* get-raw-key-value */ __wt_cursor_set_key, /* set-key */ + __wt_cursor_set_raw_key, /* set-key */ __wt_cursor_set_value, /* set-value */ __curfile_compare, /* compare */ __curfile_equals, /* equals */ diff --git a/src/third_party/wiredtiger/src/cursor/cur_hs.c b/src/third_party/wiredtiger/src/cursor/cur_hs.c index c3a412792ef..ed2c6a06d97 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_hs.c +++ b/src/third_party/wiredtiger/src/cursor/cur_hs.c @@ -1232,6 +1232,7 @@ __wt_curhs_open(WT_SESSION_IMPL *session, WT_CURSOR *owner, WT_CURSOR **cursorp) __wt_cursor_get_value, /* get-value */ __wt_cursor_get_raw_key_value_notsup, /* get-raw-key-value */ __curhs_set_key, /* set-key */ + __wt_cursor_set_raw_key, /* set-key */ __curhs_set_value, /* set-value */ __curhs_compare, /* compare */ __wt_cursor_equals_notsup, /* equals */ diff --git a/src/third_party/wiredtiger/src/cursor/cur_index.c b/src/third_party/wiredtiger/src/cursor/cur_index.c index 6f39723b0f2..3e4b894c270 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_index.c +++ b/src/third_party/wiredtiger/src/cursor/cur_index.c @@ -564,6 +564,7 @@ __wt_curindex_open(WT_SESSION_IMPL *session, const char *uri, WT_CURSOR *owner, __curindex_get_value, /* get-value */ __wt_cursor_get_raw_key_value_notsup, /* get-raw-key-value */ __wt_cursor_set_key, /* set-key */ + __wt_cursor_set_raw_key, /* set-key */ __curindex_set_value, /* set-value */ __curindex_compare, /* compare */ __wt_cursor_equals, /* equals */ diff --git a/src/third_party/wiredtiger/src/cursor/cur_join.c b/src/third_party/wiredtiger/src/cursor/cur_join.c index e568ebb69a6..a31235c74ca 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_join.c +++ b/src/third_party/wiredtiger/src/cursor/cur_join.c @@ -563,6 +563,7 @@ __curjoin_entry_member( __wt_cursor_get_value, /* get-value */ __wt_cursor_get_raw_key_value, /* get-raw-key-value */ __wt_cursor_set_key, /* set-key */ + __wt_cursor_set_raw_key, /* set-key */ __wt_cursor_set_value, /* set-value */ __wt_cursor_compare_notsup, /* compare */ __wt_cursor_equals_notsup, /* equals */ @@ -1120,12 +1121,12 @@ __curjoin_pack_recno( WT_SESSION_IMPL *session, uint64_t r, uint8_t *buf, size_t bufsize, WT_ITEM *item) { WT_SESSION *wtsession; - size_t sz; + size_t sz, used_bytes; wtsession = (WT_SESSION *)session; WT_RET(wiredtiger_struct_size(wtsession, &sz, "r", r)); WT_ASSERT(session, sz < bufsize); - WT_RET(wiredtiger_struct_pack(wtsession, buf, bufsize, "r", r)); + WT_RET(wiredtiger_struct_pack(wtsession, buf, bufsize, &used_bytes, "r", r)); item->size = sz; item->data = buf; return (0); @@ -1213,6 +1214,7 @@ __wt_curjoin_open(WT_SESSION_IMPL *session, const char *uri, WT_CURSOR *owner, c __curjoin_get_value, /* get-value */ __wt_cursor_get_raw_key_value_notsup, /* get-raw-key-value */ __wt_cursor_set_key_notsup, /* set-key */ + __wt_cursor_set_raw_key, /* */ __wt_cursor_set_value_notsup, /* set-value */ __wt_cursor_compare_notsup, /* compare */ __wt_cursor_equals_notsup, /* equals */ diff --git a/src/third_party/wiredtiger/src/cursor/cur_log.c b/src/third_party/wiredtiger/src/cursor/cur_log.c index 439933dd527..5a667416478 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_log.c +++ b/src/third_party/wiredtiger/src/cursor/cur_log.c @@ -329,6 +329,7 @@ __wt_curlog_open(WT_SESSION_IMPL *session, const char *uri, const char *cfg[], W __wt_cursor_get_value, /* get-value */ __wt_cursor_get_raw_key_value, /* get-raw-key-value */ __wt_cursor_set_key, /* set-key */ + __wt_cursor_set_raw_key, /* */ __wt_cursor_set_value, /* set-value */ __curlog_compare, /* compare */ __wt_cursor_equals, /* equals */ diff --git a/src/third_party/wiredtiger/src/cursor/cur_metadata.c b/src/third_party/wiredtiger/src/cursor/cur_metadata.c index f202c591305..e0320aeb93d 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_metadata.c +++ b/src/third_party/wiredtiger/src/cursor/cur_metadata.c @@ -582,6 +582,7 @@ __wt_curmetadata_open(WT_SESSION_IMPL *session, const char *uri, WT_CURSOR *owne __wt_cursor_get_value, /* get-value */ __wt_cursor_get_raw_key_value, /* get-raw-key-value */ __wt_cursor_set_key, /* set-key */ + __wt_cursor_set_raw_key, /* */ __wt_cursor_set_value, /* set-value */ __curmetadata_compare, /* compare */ __wt_cursor_equals, /* equals */ diff --git a/src/third_party/wiredtiger/src/cursor/cur_stat.c b/src/third_party/wiredtiger/src/cursor/cur_stat.c index c34fabb19c6..31d806a7b5d 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_stat.c +++ b/src/third_party/wiredtiger/src/cursor/cur_stat.c @@ -624,26 +624,27 @@ __wt_curstat_open(WT_SESSION_IMPL *session, const char *uri, WT_CURSOR *other, c __curstat_get_value, /* get-value */ __wt_cursor_get_raw_key_value_notsup, /* get-raw-key-value */ __curstat_set_key, /* set-key */ - __curstat_set_value, /* set-value */ - __wt_cursor_compare_notsup, /* compare */ - __wt_cursor_equals_notsup, /* equals */ - __curstat_next, /* next */ - __curstat_prev, /* prev */ - __curstat_reset, /* reset */ - __curstat_search, /* search */ - __wt_cursor_search_near_notsup, /* search-near */ - __wt_cursor_notsup, /* insert */ - __wt_cursor_modify_notsup, /* modify */ - __wt_cursor_notsup, /* update */ - __wt_cursor_notsup, /* remove */ - __wt_cursor_notsup, /* reserve */ - __wt_cursor_config_notsup, /* reconfigure */ - __wt_cursor_notsup, /* largest_key */ - __wt_cursor_config_notsup, /* bound */ - __wt_cursor_notsup, /* cache */ - __wt_cursor_reopen_notsup, /* reopen */ - __wt_cursor_checkpoint_id, /* checkpoint ID */ - __curstat_close); /* close */ + __wt_cursor_set_raw_key, /* */ + __curstat_set_value, /* set-value */ + __wt_cursor_compare_notsup, /* compare */ + __wt_cursor_equals_notsup, /* equals */ + __curstat_next, /* next */ + __curstat_prev, /* prev */ + __curstat_reset, /* reset */ + __curstat_search, /* search */ + __wt_cursor_search_near_notsup, /* search-near */ + __wt_cursor_notsup, /* insert */ + __wt_cursor_modify_notsup, /* modify */ + __wt_cursor_notsup, /* update */ + __wt_cursor_notsup, /* remove */ + __wt_cursor_notsup, /* reserve */ + __wt_cursor_config_notsup, /* reconfigure */ + __wt_cursor_notsup, /* largest_key */ + __wt_cursor_config_notsup, /* bound */ + __wt_cursor_notsup, /* cache */ + __wt_cursor_reopen_notsup, /* reopen */ + __wt_cursor_checkpoint_id, /* checkpoint ID */ + __curstat_close); /* close */ WT_CURSOR *cursor; WT_CURSOR_STAT *cst; WT_DECL_RET; diff --git a/src/third_party/wiredtiger/src/cursor/cur_table.c b/src/third_party/wiredtiger/src/cursor/cur_table.c index 9e4a3b2307a..b11f71e0654 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_table.c +++ b/src/third_party/wiredtiger/src/cursor/cur_table.c @@ -89,6 +89,7 @@ __wt_apply_single_idx(WT_SESSION_IMPL *session, WT_INDEX *idx, WT_CURSOR *cur, __wt_cursor_get_value, /* get-value */ __wt_cursor_get_raw_key_value, /* get-raw-key-value */ __wt_cursor_set_key, /* set-key */ + __wt_cursor_set_raw_key, /* */ __wt_cursor_set_value, /* set-value */ __wt_cursor_compare_notsup, /* compare */ __wt_cursor_equals_notsup, /* equals */ @@ -1051,6 +1052,7 @@ __wt_curtable_open(WT_SESSION_IMPL *session, const char *uri, WT_CURSOR *owner, __wt_curtable_get_value, /* get-value */ __wt_cursor_get_raw_key_value_notsup, /* get-raw-key-value */ __wt_curtable_set_key, /* set-key */ + __wt_cursor_set_raw_key, /* set-key */ __wt_curtable_set_value, /* set-value */ __curtable_compare, /* compare */ __wt_cursor_equals, /* equals */ diff --git a/src/third_party/wiredtiger/src/cursor/cur_version.c b/src/third_party/wiredtiger/src/cursor/cur_version.c index c7cb50e7a1f..dafc8042812 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_version.c +++ b/src/third_party/wiredtiger/src/cursor/cur_version.c @@ -603,6 +603,7 @@ __wt_curversion_open(WT_SESSION_IMPL *session, const char *uri, WT_CURSOR *owner __curversion_get_value, /* get-value */ __wt_cursor_get_raw_key_value_notsup, /* get-raw-key-value */ __curversion_set_key, /* set-key */ + __wt_cursor_set_raw_key, /* */ __wt_cursor_set_value_notsup, /* set-value */ __wt_cursor_compare_notsup, /* compare */ __wt_cursor_equals_notsup, /* equals */ diff --git a/src/third_party/wiredtiger/src/include/cursor.h b/src/third_party/wiredtiger/src/include/cursor.h index 1039e915780..641f9a73749 100644 --- a/src/third_party/wiredtiger/src/include/cursor.h +++ b/src/third_party/wiredtiger/src/include/cursor.h @@ -14,29 +14,29 @@ /* * Initialize a static WT_CURSOR structure. */ -#define WT_CURSOR_STATIC_INIT(n, get_key, get_value, get_raw_key_value, set_key, set_value, \ - compare, equals, next, prev, reset, search, search_near, insert, modify, update, remove, \ - reserve, reconfigure, largest_key, bound, cache, reopen, checkpoint_id, close) \ - static const WT_CURSOR n = { \ - NULL, /* session */ \ - NULL, /* uri */ \ - NULL, /* key_format */ \ - NULL, /* value_format */ \ - get_key, get_value, get_raw_key_value, set_key, set_value, compare, equals, next, prev, \ - reset, search, search_near, insert, modify, update, remove, reserve, checkpoint_id, close, \ - largest_key, reconfigure, bound, cache, reopen, 0, /* uri_hash */ \ - {NULL, NULL}, /* TAILQ_ENTRY q */ \ - 0, /* recno key */ \ - {0}, /* recno raw buffer */ \ - NULL, /* json_private */ \ - NULL, /* lang_private */ \ - {NULL, 0, NULL, 0, 0}, /* WT_ITEM key */ \ - {NULL, 0, NULL, 0, 0}, /* WT_ITEM value */ \ - 0, /* int saved_err */ \ - NULL, /* internal_uri */ \ - {NULL, 0, NULL, 0, 0}, /* WT_ITEM lower bound */ \ - {NULL, 0, NULL, 0, 0}, /* WT_ITEM upper bound */ \ - 0 /* uint32_t flags */ \ +#define WT_CURSOR_STATIC_INIT(n, get_key, get_value, get_raw_key_value, set_key, set_raw_key, \ + set_value, compare, equals, next, prev, reset, search, search_near, insert, modify, update, \ + remove, reserve, reconfigure, largest_key, bound, cache, reopen, checkpoint_id, close) \ + static const WT_CURSOR n = { \ + NULL, /* session */ \ + NULL, /* uri */ \ + NULL, /* key_format */ \ + NULL, /* value_format */ \ + get_key, get_value, get_raw_key_value, set_raw_key, set_key, set_value, compare, equals, \ + next, prev, reset, search, search_near, insert, modify, update, remove, reserve, \ + checkpoint_id, close, largest_key, reconfigure, bound, cache, reopen, 0, /* uri_hash */ \ + {NULL, NULL}, /* TAILQ_ENTRY q */ \ + 0, /* recno key */ \ + {0}, /* recno raw buffer */ \ + NULL, /* json_private */ \ + NULL, /* lang_private */ \ + {NULL, 0, NULL, 0, 0}, /* WT_ITEM key */ \ + {NULL, 0, NULL, 0, 0}, /* WT_ITEM value */ \ + 0, /* int saved_err */ \ + NULL, /* internal_uri */ \ + {NULL, 0, NULL, 0, 0}, /* WT_ITEM lower bound */ \ + {NULL, 0, NULL, 0, 0}, /* WT_ITEM upper bound */ \ + 0 /* uint32_t flags */ \ } /* Call a function without the evict reposition cursor flag, restore afterwards. */ diff --git a/src/third_party/wiredtiger/src/include/packing_inline.h b/src/third_party/wiredtiger/src/include/packing_inline.h index e0aeeb19354..acb4f697146 100644 --- a/src/third_party/wiredtiger/src/include/packing_inline.h +++ b/src/third_party/wiredtiger/src/include/packing_inline.h @@ -629,12 +629,9 @@ __unpack_read(WT_SESSION_IMPL *session, WT_PACK_VALUE *pv, const uint8_t **pp, s } \ } while (0) -/* - * __wt_struct_packv -- - * Pack a byte string (va_list version). - */ static WT_INLINE int -__wt_struct_packv(WT_SESSION_IMPL *session, void *buffer, size_t size, const char *fmt, va_list ap) +__wt_struct_packv_size(WT_SESSION_IMPL *session, void *buffer, size_t size, size_t *used_bytes, + const char *fmt, va_list ap) { WT_DECL_PACK_VALUE(pv); WT_DECL_RET; @@ -647,7 +644,9 @@ __wt_struct_packv(WT_SESSION_IMPL *session, void *buffer, size_t size, const cha if (fmt[0] != '\0' && fmt[1] == '\0') { pv.type = fmt[0]; WT_PACK_GET(session, pv, ap); - return (__pack_write(session, &pv, &p, size)); + WT_RET(__pack_write(session, &pv, &p, size)); + *used_bytes = (size_t)(p - (uint8_t *)buffer); + return (0); } WT_RET(__pack_init(session, &pack, fmt)); @@ -660,9 +659,22 @@ __wt_struct_packv(WT_SESSION_IMPL *session, void *buffer, size_t size, const cha /* Be paranoid - __pack_write should never overflow. */ WT_ASSERT(session, p <= end); + *used_bytes = (size_t)(p - (uint8_t *)buffer); + return (0); } +/* + * __wt_struct_packv -- + * Pack a byte string (va_list version). + */ +static WT_INLINE int +__wt_struct_packv(WT_SESSION_IMPL *session, void *buffer, size_t size, const char *fmt, va_list ap) +{ + size_t used_bytes; + return __wt_struct_packv_size(session, buffer, size, &used_bytes, fmt, ap); +} + /* * __wt_struct_sizev -- * Calculate the size of a packed byte string (va_list version). diff --git a/src/third_party/wiredtiger/src/include/wiredtiger.in b/src/third_party/wiredtiger/src/include/wiredtiger.in index 0ecef951675..395952eb36e 100644 --- a/src/third_party/wiredtiger/src/include/wiredtiger.in +++ b/src/third_party/wiredtiger/src/include/wiredtiger.in @@ -280,6 +280,8 @@ struct __wt_cursor { */ int __F(get_raw_key_value)(WT_CURSOR *cursor, WT_ITEM* key, WT_ITEM* value); + void __F(set_raw_key)(WT_CURSOR *cursor, WT_ITEM* key); + /*! * Set the key for the next operation. * @@ -3587,7 +3589,7 @@ struct __wt_event_handler { * @errors */ int wiredtiger_struct_pack(WT_SESSION *session, - void *buffer, size_t len, const char *format, ...) + void *buffer, size_t len, size_t *used_bytes, const char *format, ...) WT_ATTRIBUTE_LIBRARY_VISIBLE; /*! diff --git a/src/third_party/wiredtiger/src/lsm/lsm_cursor.c b/src/third_party/wiredtiger/src/lsm/lsm_cursor.c index 80be5ff314c..0e3d0941fcc 100644 --- a/src/third_party/wiredtiger/src/lsm/lsm_cursor.c +++ b/src/third_party/wiredtiger/src/lsm/lsm_cursor.c @@ -1686,6 +1686,7 @@ __wt_clsm_open(WT_SESSION_IMPL *session, const char *uri, WT_CURSOR *owner, cons __wt_cursor_get_value, /* get-value */ __wt_cursor_get_raw_key_value, /* get-value */ __wt_cursor_set_key, /* set-key */ + __wt_cursor_set_raw_key, /* set-key */ __wt_cursor_set_value, /* set-value */ __clsm_compare, /* compare */ __wt_cursor_equals, /* equals */ diff --git a/src/third_party/wiredtiger/src/packing/pack_api.c b/src/third_party/wiredtiger/src/packing/pack_api.c index f9d72f89093..5d241187dca 100644 --- a/src/third_party/wiredtiger/src/packing/pack_api.c +++ b/src/third_party/wiredtiger/src/packing/pack_api.c @@ -13,7 +13,8 @@ * Pack a byte string (extension API). */ int -wiredtiger_struct_pack(WT_SESSION *wt_session, void *buffer, size_t len, const char *format, ...) +wiredtiger_struct_pack( + WT_SESSION *wt_session, void *buffer, size_t len, size_t *used_bytes, const char *format, ...) { WT_DECL_RET; WT_SESSION_IMPL *session; @@ -22,7 +23,7 @@ wiredtiger_struct_pack(WT_SESSION *wt_session, void *buffer, size_t len, const c session = (WT_SESSION_IMPL *)wt_session; va_start(ap, format); - ret = __wt_struct_packv(session, buffer, len, format, ap); + ret = __wt_struct_packv_size(session, buffer, len, used_bytes, format, ap); va_end(ap); return (ret); -- 2.34.1