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

interval/generic: improve randomized testing, fix upper bound bug #51939

Merged

Conversation

nvanbenschoten
Copy link
Member

In an effort to track down the bug that triggered #51913, this commit
ports the randomized interval btree benchmarks to also be unit tests.
This allows us to run invariant checks (see btree.Verify) on randomized
tree configurations.

Doing so revealed a violation of the isUpperBoundCorrect invariant.
This was determined to be a bug in node.removeMax. When removing an
item from a grandchild node, we were failing to adjust the upper bound
of the child node. It doesn't look like this could cause user-visible
effects because the upper bound of a subtree is only ever decreased on
removal, so at worst, this caused searches in the tree to do more work
than strictly necessary. Still, this is a good bug to fix and it's
encouraging that the new randomized testing using the existing invariant
validation caught it.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@irfansharif irfansharif left a comment

Choose a reason for hiding this comment

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

LGTM, I thought this was a bigger diff than it was. Now that we're sharing the same code for the benchmarks+tests, would it make sense to skip the verification code when running the benchmarks?

Reviewed 8 of 8 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @nvanbenschoten)


pkg/util/interval/generic/internal/interval_btree_tmpl.go, line 627 at r1 (raw file):

// adjustUpperBoundOnRemoval adjusts the upper key bound for this node
// given a item and an optional child node that was removed. Returns

s/given a/given an

In an effort to track down the bug that triggered cockroachdb#51913, this commit
ports the randomized interval btree benchmarks to also be unit tests.
This allows us to run invariant checks (see `btree.Verify`) on randomized
tree configurations.

Doing so revealed a violation of the `isUpperBoundCorrect` invariant.
This was determined to be a bug in `node.removeMax`. When removing an
item from a grandchild node, we were failing to adjust the upper bound
of the child node. It doesn't look like this could cause user-visible
effects because the upper bound of a subtree is only ever decreased on
removal, so at worst, this caused searches in the tree to do more work
than strictly necessary. Still, this is a good bug to fix and it's
encouraging that the new randomized testing using the existing invariant
validation caught it.
This was fallout from a previous `s/latch/item/g`.
Copy link
Member Author

@nvanbenschoten nvanbenschoten left a comment

Choose a reason for hiding this comment

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

TFTR!

Now that we're sharing the same code for the benchmarks+tests, would it make sense to skip the verification code when running the benchmarks?

Yep, we are, see the type switch in verify.

bors r+

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @irfansharif)


pkg/util/interval/generic/internal/interval_btree_tmpl.go, line 627 at r1 (raw file):

Previously, irfansharif (irfan sharif) wrote…

s/given a/given an

Good catch. I think I s/latch/item/g at one point, which is why we have this issue in a number of places. Fixed.

@craig
Copy link
Contributor

craig bot commented Aug 3, 2020

Build succeeded:

@craig craig bot merged commit 6ff0528 into cockroachdb:master Aug 3, 2020
@nvanbenschoten nvanbenschoten deleted the nvanbenschoten/btreeRandomTest branch August 4, 2020 18:00
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.

3 participants