Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the bug with using the user comparator to compare prefix. #12862

Closed

Conversation

wqshr12345
Copy link
Contributor

@wqshr12345 wqshr12345 commented Jul 13, 2024

Fixes #12855

@@ -1280,11 +1280,9 @@ void LevelIterator::Seek(const Slice& target) {
ts_sz);
if (prefix_extractor_->InDomain(target_user_key_without_ts) &&
(!prefix_extractor_->InDomain(next_file_first_user_key_without_ts) ||
user_comparator_.CompareWithoutTimestamp(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. I think the original code should work fine too. A prefix is a continuous group, when determine if two groups are actually the same group, it should be ok to use the user comparator's logic.

This is checking the result to be equal or not, which is the same as what BytewiseComparator does and what ReverseBytewiseComparator does:

return a.compare(b);

return -a.compare(b);

I'm checking this since this seems to be a very hot code path, if something is wrong with it, it would be great to include a unit test to show case what bug this fixes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, the original code performs well in the two comparators you provided. But what I want to express is that the comparator is not responsible for comparing the values of the prefix (at least there is no such requirement in its comments). If it is a user-defined comparator, it may not support comparing prefixes, resulting in errors. Actually, our custom comparator does not support comparing prefixes, so an error occurred here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want to understand the issue better, would you mind giving an example of what the custom comparator is doing and what kind of error is encountered for comparing which prefixes etc?

Copy link
Contributor

@jowlyzhang jowlyzhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for this fix. Now I think about it more, this is a good fix and help make this handling be consistent with all the other handling inside of RocksDB regarding prefix.

@facebook-github-bot
Copy link
Contributor

@jowlyzhang has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@jowlyzhang merged this pull request in 755010f.

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

Successfully merging this pull request may close these issues.

A bug when using a prefix_extractor with a comparator.
3 participants