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 bug when prefix_same_as_start = true and keys not in domain #5923

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

siying
Copy link
Contributor

@siying siying commented Oct 15, 2019

Summary: Prefix extractor needs to be invoked for a key only when it is in domain. However, when prefix_same_as_start = true, this assumption is broken. The fix is to add InDomain() check before any Transform() call when prefix_same_as_start = true.

Test Plan: Add a unit test to cover prefix_same_as_start = true with seek keys and keys on DB not in domain.

Summary: Prefix extractor needs to be invoked for a key only when it is in domain. However, when prefix_same_as_start = true, this assumption is broken. The fix is to add InDomain() check before any Transform() call when prefix_same_as_start = true.

Test Plan: Add a unit test to cover prefix_same_as_start = true with seek keys and keys on DB not in domain.
assert(prefix_extractor_ != nullptr);
assert(!prefix_same_as_start_ || prefix_extractor_ != nullptr);
if (valid_ && prefix_same_as_start_ &&
prefix_extractor_->InDomain(saved_key_.GetUserKey())) {
Copy link
Contributor

@riversand963 riversand963 Jan 23, 2020

Choose a reason for hiding this comment

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

If valid_, can prefix_extractor_->InDomain(saved_key_.GetUserKey()) be false?

@ltamasi
Copy link
Contributor

ltamasi commented Jan 24, 2020

If prefix_same_as_start==true but the seek target is not in domain for the prefix extractor, the Seek methods currently behave as if prefix_same_as_start was not set at all; wouldn't it be better to simply set valid_ to false and bail out?

ro.prefix_same_as_start = true;
std::unique_ptr<Iterator> iter(NewIterator(ro));

// Behavior of prefix_same_as_start = ture with seek key not in domain
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this is one of the cases I was thinking about where we could consider making the iterator invalid.

Also, there's a typo ("true").

ASSERT_FALSE(iter->Valid());
ASSERT_OK(iter->status());

// Behavior of prefix_same_as_start = ture + SeekForPrev() is not defined
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here; also, it's SeekToFirst/SeekToLast, not SeekForPrev. (We could also consider actually adding a test for say, SeekForPrev("e").)

@facebook-github-bot
Copy link
Contributor

Hi @siying!

Thank you for your pull request.

We require contributors to sign our Contributor License Agreement, and yours needs attention.

You currently have a record in our system, but the CLA is no longer valid, and will need to be resubmitted.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@mzygQAQ
Copy link

mzygQAQ commented Jul 6, 2023

hi, Any updates in this issue ? we have used PrefixExtractor, but not all keys meet the InDomain of PrefixExtractor. When we enable total_ order_ seek, but prefix_same_as_ start still on, follow the comments in ReadOptions, prefix_same_as_ start=true && total_ order_ seek=true, prefixScan is not effective. However, when the Iterator is actually used, the process will be aborted because the traversal does not meet the InDomain constraint~

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.

5 participants