diff options
author | Etienne Petrel <etienne.petrel@mongodb.com> | 2022-09-15 23:26:47 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-09-16 00:09:12 +0000 |
commit | e93608f365efaf0cceb19ad91c8e7c813a3a0caa (patch) | |
tree | 869c5633bc5c9b338cf8750e3e3d1a2c5f6d614d | |
parent | 38af3bf86eb1be7cea7870f26872ec1a19c9eec7 (diff) | |
download | mongo-e93608f365efaf0cceb19ad91c8e7c813a3a0caa.tar.gz |
Import wiredtiger: de9b556a851a993cf6d7d207191cdccce8a46017 from branch mongodb-master
ref: 88a8cfc930..de9b556a85
for: 6.2.0-rc0
WT-9578 Implement the bounded cursor API for the Dump cursor (#8258)
-rw-r--r-- | src/third_party/wiredtiger/import.data | 2 | ||||
-rw-r--r-- | src/third_party/wiredtiger/src/cursor/cur_dump.c | 15 | ||||
-rw-r--r-- | src/third_party/wiredtiger/test/suite/test_cursor_bound16.py | 125 |
3 files changed, 140 insertions, 2 deletions
diff --git a/src/third_party/wiredtiger/import.data b/src/third_party/wiredtiger/import.data index 3118bd1b22c..df31cd36bd8 100644 --- a/src/third_party/wiredtiger/import.data +++ b/src/third_party/wiredtiger/import.data @@ -2,5 +2,5 @@ "vendor": "wiredtiger", "github": "wiredtiger/wiredtiger.git", "branch": "mongodb-master", - "commit": "88a8cfc9307634879f155531cd2a79af703a887a" + "commit": "de9b556a851a993cf6d7d207191cdccce8a46017" } diff --git a/src/third_party/wiredtiger/src/cursor/cur_dump.c b/src/third_party/wiredtiger/src/cursor/cur_dump.c index bffd997a3ed..46ba23b7e0e 100644 --- a/src/third_party/wiredtiger/src/cursor/cur_dump.c +++ b/src/third_party/wiredtiger/src/cursor/cur_dump.c @@ -323,6 +323,19 @@ __curdump_set_value(WT_CURSOR *cursor, ...) return (child->op(child)); \ } +/* + * __curdump_bound -- + * WT_CURSOR::bound for dump cursors. + */ +static int +__curdump_bound(WT_CURSOR *cursor, const char *config) +{ + WT_CURSOR_DUMP *cdump; + + cdump = (WT_CURSOR_DUMP *)cursor; + return (cdump->child->bound(cdump->child, config)); +} + WT_CURDUMP_PASS(next) WT_CURDUMP_PASS(prev) WT_CURDUMP_PASS(reset) @@ -397,7 +410,7 @@ __wt_curdump_create(WT_CURSOR *child, WT_CURSOR *owner, WT_CURSOR **cursorp) __wt_cursor_notsup, /* reserve */ __wt_cursor_config_notsup, /* reconfigure */ __wt_cursor_notsup, /* largest_key */ - __wt_cursor_config_notsup, /* bound */ + __curdump_bound, /* bound */ __wt_cursor_notsup, /* cache */ __wt_cursor_reopen_notsup, /* reopen */ __wt_cursor_checkpoint_id, /* checkpoint ID */ diff --git a/src/third_party/wiredtiger/test/suite/test_cursor_bound16.py b/src/third_party/wiredtiger/test/suite/test_cursor_bound16.py new file mode 100644 index 00000000000..a1ae5c859a5 --- /dev/null +++ b/src/third_party/wiredtiger/test/suite/test_cursor_bound16.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python +# +# Public Domain 2014-present MongoDB, Inc. +# Public Domain 2008-2014 WiredTiger, Inc. +# +# This is free and unencumbered software released into the public domain. +# +# Anyone is free to copy, modify, publish, use, compile, sell, or +# distribute this software, either in source code form or as a compiled +# binary, for any purpose, commercial or non-commercial, and by any +# means. +# +# In jurisdictions that recognize copyright laws, the author or authors +# of this software dedicate any and all copyright interest in the +# software to the public domain. We make this dedication for the benefit +# of the public at large and to the detriment of our heirs and +# successors. We intend this dedication to be an overt act of +# relinquishment in perpetuity of all present and future rights to this +# software under copyright law. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +import wiredtiger, wttest +from wtscenario import make_scenarios +from wtbound import bound_base + +# test_cursor_bound16.py +# Testing basic scenarios with cursor bound functionality on dump cursors. +class test_cursor_bound16(bound_base): + file_name = 'test_cursor_bound16' + key_format = "S" + value_format = "S" + start_key = None + end_key = None + + types = [ + ('file', dict(uri='file:')), + ('table', dict(uri='table:')), + ] + + dump_options = [ + ('dump_print', dict(dumpopt='print')), + ('dump_hex', dict(dumpopt='hex')), + ] + + scenarios = make_scenarios(dump_options, types) + + def create_session_and_cursor(self): + uri = self.uri + self.file_name + create_params = 'value_format={},key_format={}'.format(self.value_format, self.key_format) + self.session.create(uri, create_params) + + cursor = self.session.open_cursor(uri, None, None) + self.session.begin_transaction() + + for i in range(20, 80): + cursor[str(i)] = self.gen_val("value" + str(i)) + self.session.commit_transaction() + + self.start_key = self.gen_dump_key(20) + self.end_key = self.gen_dump_key(80) + + def gen_dump_key(self, key): + if (self.dumpopt == "hex"): + return str(key).encode().hex() + "00" + else: + return str(key) + "\\00" + + def test_dump_cursor(self): + self.create_session_and_cursor() + + dumpopt = "dump={}".format(self.dumpopt) + dumpcurs = self.session.open_cursor(self.uri + self.file_name, + None, dumpopt) + + # Set bounds at lower key 30 and upper key at 50. + self.set_bounds(dumpcurs, self.gen_dump_key(30), "lower") + self.set_bounds(dumpcurs, self.gen_dump_key(50), "upper") + self.cursor_traversal_bound(dumpcurs, self.gen_dump_key(30), self.gen_dump_key(50), True, 21) + self.cursor_traversal_bound(dumpcurs, self.gen_dump_key(30), self.gen_dump_key(50), False, 21) + + # Test basic search near scenarios. + dumpcurs.set_key(self.gen_dump_key(20)) + self.assertEqual(dumpcurs.search_near(), 1) + self.assertEqual(dumpcurs.get_key(), self.gen_dump_key(30)) + + dumpcurs.set_key(self.gen_dump_key(40)) + self.assertEqual(dumpcurs.search_near(), 0) + self.assertEqual(dumpcurs.get_key(), self.gen_dump_key(40)) + + dumpcurs.set_key(self.gen_dump_key(60)) + self.assertEqual(dumpcurs.search_near(), -1) + self.assertEqual(dumpcurs.get_key(), self.gen_dump_key(50)) + + # Test basic search scenarios. + dumpcurs.set_key(self.gen_dump_key(20)) + self.assertEqual(dumpcurs.search(), wiredtiger.WT_NOTFOUND) + + dumpcurs.set_key(self.gen_dump_key(40)) + self.assertEqual(dumpcurs.search(), 0) + + dumpcurs.set_key(self.gen_dump_key(60)) + self.assertEqual(dumpcurs.search(), wiredtiger.WT_NOTFOUND) + + # Test that cursor resets the bounds. + self.assertEqual(dumpcurs.reset(), 0) + self.cursor_traversal_bound(dumpcurs, self.start_key, self.end_key, True, 60) + self.cursor_traversal_bound(dumpcurs, self.start_key, self.end_key, False, 60) + + # Test that cursor action clear works and clears the bounds. + self.set_bounds(dumpcurs, self.gen_dump_key(30), "lower") + self.set_bounds(dumpcurs, self.gen_dump_key(50), "upper") + self.assertEqual(dumpcurs.bound("action=clear"), 0) + self.cursor_traversal_bound(dumpcurs, self.start_key, self.end_key, True, 60) + self.cursor_traversal_bound(dumpcurs, self.start_key, self.end_key, False, 60) + + dumpcurs.close() + +if __name__ == '__main__': + wttest.run() |