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

implement iterate_upper_bound for txn iterators #5105

Closed

Conversation

miasantreble
Copy link
Contributor

@miasantreble miasantreble commented Mar 26, 2019

Current implementation of current_over_upper_bound_ fails to take into consideration that keys might be invalid in either base iterator or delta iterator. Calling key() in such scenario will lead to assertion failure and runtime errors.
This PR addresses the bug by adding check for valid keys before calling IsOverUpperBound(), also added test coverage for iterate_upper_bound usage in BaseDeltaIterator
(trying to land PR #4702 once again)
Test plan:

  • make check
  • run mysqltest.sh

@miasantreble miasantreble added the WIP Work in progress label Mar 26, 2019
@miasantreble miasantreble changed the title [WIP] implement iterate_upper_bound for txn iterators implement iterate_upper_bound for txn iterators Mar 26, 2019
@miasantreble miasantreble requested a review from siying March 26, 2019 04:58
@miasantreble miasantreble removed the WIP Work in progress label Mar 26, 2019
@miasantreble miasantreble force-pushed the txn-iterator-upper-bound branch from af5fbcd to 848036d Compare March 26, 2019 05:13
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

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

@facebook-github-bot
Copy link
Contributor

@miasantreble has updated the pull request. Re-import the pull request

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

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

@siying
Copy link
Contributor

siying commented Mar 26, 2019

Did we understand why the randomized tests failed to catch the bug exposed by MyRocks now?

@miasantreble
Copy link
Contributor Author

I think it's because inside the infinite loop, the update to current_at_base_ may be delayed, so it's not more reliable to call key() to get the most up to date key. this commit contains the fix 848036d and got verified in mysqltest

@siying
Copy link
Contributor

siying commented Mar 26, 2019

@miasantreble the question is, why didn't the randomized test catch it?

Copy link
Contributor

@siying siying left a comment

Choose a reason for hiding this comment

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

Would it be clearer if we simply check upper bound in AdvanceDelta() and AdvanceBase() instead? Would we avoid changing the complicated logic inside UpdateCurrent()?

@@ -264,32 +276,38 @@ class BaseDeltaIterator : public Iterator {
} else if (!delta_iterator_->status().ok()) {
// Expose the error status and stop.
current_at_base_ = false;
return;
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

It's safer to just return here. I am worried about by mistake we access the data while status is not OK. It always makes things hard to reason about.

}
equal_keys_ = false;
if (!BaseValid()) {
if (!base_iterator_->status().ok()) {
// Expose the error status and stop.
current_at_base_ = true;
return;
break;
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. Safer to just return.

}

// Base has finished.
if (!DeltaValid()) {
// Finished
return;
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

Both of delta and base are at the end. A good idea to return.

DeltaValid() && IsOverUpperBound(delta_iterator_->Entry().key);
if (current_over_upper_bound_) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we consider to do the check inside AdvanceDelta() instead?

@facebook-github-bot
Copy link
Contributor

@miasantreble has updated the pull request. Re-import the pull request

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

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

@miasantreble
Copy link
Contributor Author

ran mysqltest using latest commit 495e6c7 and no crash found

@siying
Copy link
Contributor

siying commented Mar 27, 2019

@miasantreble I think I asked the question twice, but why didn't the randomized test catch the bug we found in MyRocks test? Or would it catch it?

Copy link
Contributor

@siying siying left a comment

Choose a reason for hiding this comment

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

Actually, if we assume the upper bound is pushed down to base iterator, where the filtering is already done, we only need to do in AdvanceDelta().

@siying
Copy link
Contributor

siying commented Mar 29, 2019

Do you consider to move the check to AdvanceDelta() and leaves UpdateCurrent() alone?

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.

3 participants