Fix a bug in MultiScan that moves iterator backward#14106
Closed
cbi42 wants to merge 3 commits intofacebook:mainfrom
Closed
Fix a bug in MultiScan that moves iterator backward#14106cbi42 wants to merge 3 commits intofacebook:mainfrom
cbi42 wants to merge 3 commits intofacebook:mainfrom
Conversation
xingbowang
approved these changes
Nov 6, 2025
Contributor
xingbowang
left a comment
There was a problem hiding this comment.
Thanks for fixing this. Looks good to me.
I have 2 follow up questions.
- What if the same key span 2 files with multiple verions?
- Would engine run into some kind of dead loop? if it repeatedly do re-seek? Or there is some kind of upper level logic to ensure it only reseek once?
Contributor
Author
I don't think it makes a difference. LevelIterator::Seek() will pick the right file based on the seek key and file key ranges.
It looks like we only reseek once for a user key: Lines 564 to 567 in 37176a4 If we seek to the last internal key for a user key, I don't think it will trigger another reseek. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary: MultiScanUnexpectedSeekTarget() currently uses user key comparison to decide on the next data block for multiscan. This can cause a multiscan to move backward in the following scenario:
data block 1: ..., k@7, k@6
data block 2: k@5, ...
DB iter scan through k@7, k@6 and k@5 and decides to seek to k@0 due to option
max_sequential_skip_in_iterations. Multiscan was on data block 2, but moves to data block 1 after the seek.This can cause assertion failure in debug mode and seg fault in prod since older data blocks are unpinned and freed as we advanced a multiscan. This PR fixes the issue by forcing a multiscan to never go backward.
Test plan:
./db_iterator_test --gtest_filter="*ReseekAcrossBlocksSameUserKey*"