Truncating large table objects fails with cursor.compare: requires key be set: Invalid argument.
Here's the script:
import wiredtiger, wttest from helper import complex_populate, key_populate # test_xxx.py class test_xxx(wttest.WiredTigerTestCase): # Override WiredTigerTestCase, we have extensions. def setUpConnectionOpen(self, dir): conn = wiredtiger.wiredtiger_open(dir, 'create,cache_size=100MB,' + 'error_prefix="%s: "' % self.shortid()) return conn def test_xxx(self): uri = 'table:xxx' config = 'allocation_size=512,' +\ 'leaf_page_max=512,value_format=S,key_format=S' nentries = 10000 # works nentries = 100000 # fails complex_populate(self, uri, config, nentries - 1) # Remove most of the object. c1 = self.session.open_cursor(uri, None) c1.set_key(key_populate(c1, 5)) c2 = self.session.open_cursor(uri, None) c2.set_key(key_populate(c2, nentries - 5)) self.session.truncate(None, c1, c2, None) c1.close() c2.close() if __name__ == '__main__': wttest.run()
Here's the stack:
#0 __wt_err (session=0x805dbe420, error=22,
fmt=0x803730c22 "requires %s be set") at ../src/support/err.c:273
WT-1 0x00000008036e5f3e in __wt_cursor_kv_not_set (cursor=0x805cea200, key=1)
at ../src/cursor/cur_std.c:71
WT-2 0x00000008036e05cd in __curfile_search (cursor=0x805cea200)
at ../src/cursor/cur_file.c:175
WT-3 0x00000008036ee6cd in __wt_table_range_truncate (start=0x805cda680,
stop=0x805cda7c0) at ../src/cursor/cur_table.c:529
WT-4 0x00000008037195a0 in __wt_schema_range_truncate (session=0x805dbe420,
start=0x805cda680, stop=0x805cda7c0) at ../src/schema/schema_truncate.c:171
WT-5 0x000000080371c063 in __session_truncate (wt_session=0x805dbe420, uri=0x0,
start=0x805cda680, stop=0x805cda7c0, config=0x0)
at ../src/session/session_api.c:546
And looking at __wt_table_range_truncate, it's one of the column-group tables is getting its cursor key-is-set flags cleared:
Breakpoint 2, __wt_table_range_truncate (start=0x8015f8200, stop=0x8015f85c0) at ../src/cursor/cur_table.c:492 492 ctable = (start != NULL) ? start : stop; (gdb) p *ctable $12 = {iface = {session = 0x805d35410, uri = 0x801419520 "table:xxx", key_format = 0x8016bf10e "S", value_format = 0x8015451d0 "SiSS", get_key = 0x8036eade0 <__wt_curtable_get_key>, get_value = 0x8036eaf10 <__wt_curtable_get_value>, set_key = 0x8036eb3a0 <__wt_curtable_set_key>, set_value = 0x8036eb5d0 <__wt_curtable_set_value>, compare = 0x8036eb9d0 <__curtable_compare>, next = 0x8036ebe90 <__curtable_next>, prev = 0x8036ec200 <__curtable_prev>, reset = 0x8036ec380 <__curtable_reset>, search = 0x8036ec500 <__curtable_search>, search_near = 0x8036ec680 <__curtable_search_near>, insert = 0x8036ec850 <__curtable_insert>, update = 0x8036ecd00 <__curtable_update>, remove = 0x8036ed3b0 <__curtable_remove>, close = 0x8036ee200 <__curtable_close>, q = {tqe_next = 0x805cdd800, tqe_prev = 0x805cdd590}, recno = 0, raw_recno_buf = "\000\000\000\000\000\000\000\000", key = {data = 0x0, size = 0, flags = 0, mem = 0x0, memsize = 0}, value = {data = 0x0, size = 0, flags = 0, mem = 0x0, memsize = 0}, saved_err = 0, flags = 896}, table = 0x80141ad80, plan = 0x80153f7f0 "0vn3vr5vr1vn3vsr4vr2vn4vsr5vsrn", cfg = 0x8097ac8e0, cg_cursors = 0x80153feb0, idx_cursors = 0x0} (gdb) xxx <<<<<< xxx dumps column-group cursor flags & 0x60 $13 = 32 $14 = 64 $15 = 32 $16 = 32 $17 = 32 $18 = 32 (gdb) c Continuing. Breakpoint 2, __wt_table_range_truncate (start=0x8015f8200, stop=0x8015f85c0) at ../src/cursor/cur_table.c:492 492 ctable = (start != NULL) ? start : stop; (gdb) xxx $19 = 32 $20 = 64 $21 = 64 $22 = 0 <<<<<< cursor set-key flags are 0 $23 = 64 $24 = 64 (gdb) p ctable->cg_cursors[3].flags & 0x60 $26 = 0 (gdb) p *ctable->cg_cursors[3] $28 = {session = 0x805d35410, uri = 0x8018a7ec0 "file:xxx_cgroup4.wt", key_format = 0x8016bf11c "S", value_format = 0x805ffb090 "Si", get_key = 0x8036e5630 <__wt_cursor_get_key>, get_value = 0x8036e9a50 <__wt_cursor_get_value>, set_key = 0x8036e5740 <__wt_cursor_set_key>, set_value = 0x8036e9e20 <__wt_cursor_set_value>, compare = 0x8036df230 <__curfile_compare>, next = 0x8036df5b0 <__curfile_next>, prev = 0x8036df850 <__curfile_prev>, reset = 0x8036df9a0 <__curfile_reset>, search = 0x8036dfad0 <__curfile_search>, search_near = 0x8036dfe30 <__curfile_search_near>, insert = 0x8036e01a0 <__curfile_insert>, update = 0x8036e07f0 <__curfile_update>, remove = 0x8036e0db0 <__curfile_remove>, close = 0x8036e1320 <__curfile_close>, q = {tqe_next = 0x805cde100, tqe_prev = 0x805cddb90}, recno = 0, raw_recno_buf = "\000\000\000\000\000\000\000\000", key = { data = 0x80df54988, size = 16, flags = 0, mem = 0x80bcc63e0, memsize = 16}, value = {data = 0x80d646fe9, size = 22, flags = 0, mem = 0x0, memsize = 0}, saved_err = 0, flags = 384}