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: disable checkUncertainty on failOnMoreRecent in scanner #131093

Merged
merged 2 commits into from
Sep 26, 2024

Conversation

tbg
Copy link
Member

@tbg tbg commented Sep 20, 2024

It was possible for reads with failOnMoreRecent to hit a
ReadWithinUncertaintyIntervalError instead of the desired
WriteTooOldError. This commit disables uncertainty checks when
failOnMoreRecent is active, as the latter is a stronger check anyway.

Fixes #119681.
Fixes #131005.

Epic: none
Release note: None

Copy link

blathers-crl bot commented Sep 20, 2024

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@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.

Reviewed all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @tbg)


pkg/storage/pebble_mvcc_scanner.go line 890 at r1 (raw file):

				p.mostRecentKey = append(p.mostRecentKey, p.curUnsafeKey.Key...)
			}
			// We don't have to fall through to `p.checkUncertainty` because FIXME.

We don't have to fall through to p.checkUncertainty because we are already considering any key that is more recent to be a write-write conflict which will cause a write-too-old error to be thrown. Uncertainty checks are only needed if we would otherwise ignore keys that are more recent.

Here, we could return a WriteTooOld error immediately, but we defer that through mostRecentTS so that we return the maximum conflicting timestamp. We are trying to do the same thing below in processRangeKeys, but notice that there's no early return in the p.failOnMoreRecent case (we don't want an early return, but a continue or an else if would work). As a result, the deferred-but-preferred error case loses out to the immediate-but-less-preferred case.

This does raise the question of whether we should actually make p.failOnMoreRecent and p.checkUncertainty mutually exclusive. We could set checkUncertainty to false when failOnMoreRecent is set to true, so that we don't need to rely on the logic in each of these functions getting it right. This would be easy to do in pebbleMVCCScanner.init when setting checkUncertainty.

nvanbenschoten added a commit to nvanbenschoten/cockroach that referenced this pull request Sep 23, 2024
Noticed while reviewing cockroachdb#131093.

This commit fixes pebbleMVCCScanner to set the correct key for the
mostRecentKey field when a locking read encounters multiple keys with
more recent timestamps. These keys were added to WriteTooOld error in
52c6b1b, which had previously only been carrying the maximum
conflicting timestamp. They are currently only used for debugging.

Before this fix, we would always return the first conflicting key, even
though we correctly returned the maximum conflicting timestamp.

Epic: None
Release note: None
craig bot pushed a commit that referenced this pull request Sep 25, 2024
131220: storage: set correct key in WriteTooOld error from pebbleMVCCScanner r=nvanbenschoten a=nvanbenschoten

Noticed while reviewing #131093.

This commit fixes `pebbleMVCCScanner` to set the correct key for the `mostRecentKey` field when a locking read encounters multiple keys with more recent timestamps. These keys were added to `WriteTooOldError` in 52c6b1b, which had previously only been carrying the maximum conflicting timestamp. They are currently only used for debugging.

Before this fix, we would always return the first conflicting key, even though we correctly returned the maximum conflicting timestamp.

I'm planning to backport this to each release branch to avoid any confusing during debugging odysseys, but could be convinced that doing so is not worth the (minimal) risk.

Epic: None
Release note: None

Co-authored-by: Nathan VanBenschoten <[email protected]>
blathers-crl bot pushed a commit that referenced this pull request Sep 25, 2024
Noticed while reviewing #131093.

This commit fixes pebbleMVCCScanner to set the correct key for the
mostRecentKey field when a locking read encounters multiple keys with
more recent timestamps. These keys were added to WriteTooOld error in
52c6b1b, which had previously only been carrying the maximum
conflicting timestamp. They are currently only used for debugging.

Before this fix, we would always return the first conflicting key, even
though we correctly returned the maximum conflicting timestamp.

Epic: None
Release note: None
blathers-crl bot pushed a commit that referenced this pull request Sep 25, 2024
Noticed while reviewing #131093.

This commit fixes pebbleMVCCScanner to set the correct key for the
mostRecentKey field when a locking read encounters multiple keys with
more recent timestamps. These keys were added to WriteTooOld error in
52c6b1b, which had previously only been carrying the maximum
conflicting timestamp. They are currently only used for debugging.

Before this fix, we would always return the first conflicting key, even
though we correctly returned the maximum conflicting timestamp.

Epic: None
Release note: None
Copy link
Member Author

@tbg tbg left a comment

Choose a reason for hiding this comment

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

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


pkg/storage/pebble_mvcc_scanner.go line 890 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

We don't have to fall through to p.checkUncertainty because we are already considering any key that is more recent to be a write-write conflict which will cause a write-too-old error to be thrown. Uncertainty checks are only needed if we would otherwise ignore keys that are more recent.

Here, we could return a WriteTooOld error immediately, but we defer that through mostRecentTS so that we return the maximum conflicting timestamp. We are trying to do the same thing below in processRangeKeys, but notice that there's no early return in the p.failOnMoreRecent case (we don't want an early return, but a continue or an else if would work). As a result, the deferred-but-preferred error case loses out to the immediate-but-less-preferred case.

This does raise the question of whether we should actually make p.failOnMoreRecent and p.checkUncertainty mutually exclusive. We could set checkUncertainty to false when failOnMoreRecent is set to true, so that we don't need to rely on the logic in each of these functions getting it right. This would be easy to do in pebbleMVCCScanner.init when setting checkUncertainty.

Done. I still need to add a test.

It was possible for reads with failOnMoreRecent to hit a
ReadWithinUncertaintyIntervalError instead of the desired
WriteTooOldError. This commit disables uncertainty checks when
failOnMoreRecent is active, as the latter is a stronger check anyway.

Fixes cockroachdb#119681.
Fixes cockroachdb#131005.

Epic: none
Release note: None
Copy link
Member Author

@tbg tbg left a comment

Choose a reason for hiding this comment

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

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


pkg/storage/pebble_mvcc_scanner.go line 890 at r1 (raw file):

Previously, tbg (Tobias Grieger) wrote…

Done. I still need to add a test.

Done.

@tbg tbg changed the title storage: don't check uncertainty after passing failOnMoreRecent storage: disable checkUncertainty on failOnMoreRecent in scanner Sep 25, 2024
aa-joshi pushed a commit to aa-joshi/cockroach that referenced this pull request Sep 25, 2024
Noticed while reviewing cockroachdb#131093.

This commit fixes pebbleMVCCScanner to set the correct key for the
mostRecentKey field when a locking read encounters multiple keys with
more recent timestamps. These keys were added to WriteTooOld error in
52c6b1b, which had previously only been carrying the maximum
conflicting timestamp. They are currently only used for debugging.

Before this fix, we would always return the first conflicting key, even
though we correctly returned the maximum conflicting timestamp.

Epic: None
Release note: None
Copy link
Member

@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.

:lgtm:

Reviewed 2 of 2 files at r2, 2 of 2 files at r3, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @tbg)

@tbg tbg marked this pull request as ready for review September 25, 2024 14:39
@tbg tbg requested a review from a team as a code owner September 25, 2024 14:39
@tbg tbg added backport-24.1.x Flags PRs that need to be backported to 24.1. backport-24.2.x Flags PRs that need to be backported to 24.2 labels Sep 25, 2024
@tbg
Copy link
Member Author

tbg commented Sep 25, 2024

bors r+
TFTR!

craig bot pushed a commit that referenced this pull request Sep 25, 2024
131093: storage: disable checkUncertainty on failOnMoreRecent in scanner r=tbg a=tbg

It was possible for reads with failOnMoreRecent to hit a
ReadWithinUncertaintyIntervalError instead of the desired
WriteTooOldError. This commit disables uncertainty checks when
failOnMoreRecent is active, as the latter is a stronger check anyway.

Fixes #119681.
Fixes #131005.

Epic: none
Release note: None

Co-authored-by: Tobias Grieger <[email protected]>
@tbg tbg removed backport-24.1.x Flags PRs that need to be backported to 24.1. backport-24.2.x Flags PRs that need to be backported to 24.2 labels Sep 25, 2024
@craig
Copy link
Contributor

craig bot commented Sep 25, 2024

Build failed:

@tbg
Copy link
Member Author

tbg commented Sep 25, 2024

/github-actions-runner/_work/_temp/76ea3ede-7a2b-4587-9cc3-dbbe871ca2b7.sh: line 1: ./build/github/summarize-build.sh: No such file or directory

🤷🏽

bors r+

craig bot pushed a commit that referenced this pull request Sep 25, 2024
131093: storage: disable checkUncertainty on failOnMoreRecent in scanner r=tbg a=tbg

It was possible for reads with failOnMoreRecent to hit a
ReadWithinUncertaintyIntervalError instead of the desired
WriteTooOldError. This commit disables uncertainty checks when
failOnMoreRecent is active, as the latter is a stronger check anyway.

Fixes #119681.
Fixes #131005.

Epic: none
Release note: None

Co-authored-by: Tobias Grieger <[email protected]>
@craig
Copy link
Contributor

craig bot commented Sep 25, 2024

Build failed:

@arulajmani
Copy link
Collaborator

bors retry

@craig craig bot merged commit b4c58a0 into cockroachdb:master Sep 26, 2024
23 checks passed
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.

kv/kvnemesis: TestKVNemesisMultiNode failed kv/kvnemesis: TestKVNemesisMultiNode failed
4 participants