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

storage,libroach: Check for MaxKeys when reading from intent history #48160

Merged
merged 1 commit into from
Apr 29, 2020

Conversation

itsbilal
Copy link
Member

@itsbilal itsbilal commented Apr 29, 2020

We weren't checking for MaxKeys (or TargetBytes) being reached
in the case where we read from intent history in the MVCC scanner.
All other cases go through addAndAdvance(), which had these checks.

Almost certainly fixes #46652. Would be very surprised if it was
something else.

Release note (bug fix): Fixes a bug where a read operation in a transaction
would error out for exceeding the maximum count of results returned.

@itsbilal itsbilal self-assigned this Apr 29, 2020
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@petermattis petermattis left a comment

Choose a reason for hiding this comment

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

:lgtm: Nice find!

In the Release note: s/resturned/returned/g.

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @itsbilal, @jbowens, @petermattis, and @tbg)


pkg/storage/testdata/mvcc_histories/max_keys, line 90 at r1 (raw file):

scan: "a" -> /BYTES/val-a @0.000000001,0

# Regression test for #46652: Test appropriate termination where the MaxKeys-th

Nit: s/where/when/g (applies to similar comments elsewhere)

We weren't checking for MaxKeys (or TargetBytes) being reached
in the case where we read from intent history in the MVCC scanner.
All other cases go through addAndAdvance(), which had these checks.

Almost certainly fixes cockroachdb#46652. Would be very surprised if it was
something else.

Release note (bug fix): Fixes a bug where a read operation in a transaction
would error out for exceeding the maximum count of results returned.
Copy link
Member Author

@itsbilal itsbilal left a comment

Choose a reason for hiding this comment

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

TFTR! Addressed the nits. Also changed values in test cases to a,b,c for the 3 sequences instead of a,a,a, just to make it clear what sequence number is being read.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @itsbilal, @jbowens, and @tbg)

@tbg
Copy link
Member

tbg commented Apr 29, 2020

Thanks for the fix! The accounting around those limits looks brittle. Is there something non-invasive that we could do? Like making it impossible to add to the result set without going through the check.

@itsbilal
Copy link
Member Author

addAndAdvance is supposed to be that method, for funneling (almost) all writes through and accounting for maxKeys, etc. Changing this case to also use that would also be straightforward, and now I'm wondering if I should have done just that instead. But I felt this was less invasive as it was a more visible change (and matched it with the way it's happening in pebble).

@tbg
Copy link
Member

tbg commented Apr 29, 2020

No opposition from me. Will be easier to fix when there's only the pebble version to update anyway

@blathers-crl
Copy link

blathers-crl bot commented Apr 29, 2020

❌ The GitHub CI (Cockroach) build has failed on 3628ed90.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@itsbilal
Copy link
Member Author

TFTRs!

bors r+

@craig
Copy link
Contributor

craig bot commented Apr 29, 2020

Build failed (retrying...)

@craig
Copy link
Contributor

craig bot commented Apr 29, 2020

Build succeeded

@craig craig bot merged commit 456d01b into cockroachdb:master Apr 29, 2020
@andreimatei
Copy link
Contributor

There's an errorutil.UnexpectedWithIssueErrorf(46652) in the codebase. I think you want to delete that reference to the issue, don't you?

@itsbilal
Copy link
Member Author

Good point. @tbg what do you think about removing ^ ? There's some value to still keeping it there (since this is a bit of a speculative fix), but I'm happy with removing it too.

itsbilal added a commit to itsbilal/cockroach that referenced this pull request Apr 30, 2020
Previously, when doing an MVCCGet with the Pebble MVCC scanner,
we would advance keys after getting (or not getting) the value
we're looking for. In some cases this could result in a seek,
such as if there are too many revisions of that MVCC key. Seeks
are costly and at best avoided when it's ultimatey unnecessary.

Another side effect of doing this seek was that it would trip
an assertion in spanSet.Iterator that checked if all reads
were happening on allowed key spans. This caused TestDumpData
to fail on Pebble (but not on RocksDB since the RocksDB MVCC
scanner is specialized in C++ and doesn't flow through the same
assertion for seeks).

There's one additional change, stemming from a follow-up conversation
in cockroachdb#48160, around unifying logic for terminating an MVCC scan.
The getFromIntentHistory() case also calls into addAndAdvance()
now.

Fixes cockroachdb#48147.

Release note: None.
itsbilal added a commit to itsbilal/cockroach that referenced this pull request Apr 30, 2020
Previously, when doing an MVCCGet with the Pebble MVCC scanner,
we would advance keys after getting (or not getting) the value
we're looking for. In some cases this could result in a seek,
such as if there are too many revisions of that MVCC key. Seeks
are costly and at best avoided when it's ultimatey unnecessary.

Another side effect of doing this seek was that it would trip
an assertion in spanSet.Iterator that checked if all reads
were happening on allowed key spans. This caused TestDumpData
to fail on Pebble (but not on RocksDB since the RocksDB MVCC
scanner is specialized in C++ and doesn't flow through the same
assertion for seeks).

There's one additional change, stemming from a follow-up conversation
in cockroachdb#48160, around unifying logic for terminating an MVCC scan.
The getFromIntentHistory() case also calls into addAndAdvance()
now.

Fixes cockroachdb#48147.

Release note: None.
craig bot pushed a commit that referenced this pull request Apr 30, 2020
48239: storage: Don't advance keys in MVCCGet with Pebble r=itsbilal a=itsbilal

Previously, when doing an MVCCGet with the Pebble MVCC scanner,
we would advance keys after getting (or not getting) the value
we're looking for. In some cases this could result in a seek,
such as if there are too many revisions of that MVCC key. Seeks
are costly and at best avoided when it's ultimatey unnecessary.

Another side effect of doing this seek was that it would trip
an assertion in spanSet.Iterator that checked if all reads
were happening on allowed key spans. This caused TestDumpData
to fail on Pebble (but not on RocksDB since the RocksDB MVCC
scanner is specialized in C++ and doesn't flow through the same
assertion for seeks).

There's one additional change, stemming from a follow-up conversation
in #48160, around unifying logic for terminating an MVCC scan.
The getFromIntentHistory() case also calls into addAndAdvance()
now.

Fixes #48147.

Release note: None.

Co-authored-by: Bilal Akhtar <bilal@cockroachlabs.com>
itsbilal added a commit to itsbilal/cockroach that referenced this pull request May 1, 2020
Backport of cockroachdb#48160.

We weren't checking for MaxKeys (or TargetBytes) being reached
in the case where we read from intent history in the MVCC scanner.
All other cases go through addAndAdvance(), which had these checks.

Almost certainly fixes cockroachdb#46652. Would be very surprised if it was
something else.

Release note (bug fix): Fixes a bug where a read operation in a transaction
would error out for exceeding the maximum count of results returned.
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.

kvserver: v20.1.0-beta.3: received ... results, limit was ...
5 participants