Sitelet https://github.com/leanstore/leanstore/pull/39
Skip to content

Fix reverse iterator skipping predecessor - #39

Open
WittenYeh wants to merge 1 commit into
leanstore:masterfrom
WittenYeh:fix-btree-prev-double-decrement
Open

WittenYeh wants to merge 1 commit into
leanstore:masterfrom
WittenYeh:fix-btree-prev-double-decrement

Conversation

@WittenYeh

Copy link
Copy Markdown

Summary

  • Fix BTreePessimisticIterator::prev() skipping the immediate predecessor after crossing a leaf-page boundary through the lower-fence fallback.
  • Return immediately after lowerBound(fence) is decremented to the predecessor slot.

Root cause

When the reverse iterator cannot use the optimistic sibling jump, prev() navigates to the previous leaf using the current leaf lower fence. For a non-equal fence, lowerBound() returns the insertion position and cur is decremented once to select the correct predecessor. The fallback branch did not return afterward, so the surrounding while loop ran again and decremented cur a second time at the top of the loop. The result was the key immediately before the actual predecessor.

One reproduced case was:

query:    16497266874788550001
expected: 16497158961977953382
returned: 16497144325911138606

The expected and returned values were adjacent in sorted order. Iterator diagnostics showed lowerBound(fence) == 98, so the first decrement selected slot 97 (the expected predecessor), while the next loop iteration incorrectly selected slot 96.

Validation

  • Rebuilt LeanStore and the predecessor benchmark.
  • Inserted 1,048,576 distinct uint64 keys in random order.
  • Compared all 100,000 predecessor queries against RocksDB; all results matched.
  • Reopened the persisted LeanStore database and completed all 100,000 queries in query-only mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant