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

kv/batcheval: only expose immutable range state to commands #59009

Merged

Conversation

nvanbenschoten
Copy link
Member

The DeclareKeysFunc has always included a full RangeDescriptor, but it
has never been clear which fields in this descriptor are safe to use and
which are not when declaring keys for a request. The concern is that any
property of the RangeDescriptor that is not immutable may change between
the time that a request declares its keys to latch and the time that it
evaluates, so any assumptions based on these mutable fields may not
hold.

The quintessential example of a property of a Range that is not
immutable is its end key. It would be incorrect to declare keys between
a Range's start key and its current end key as a means of latching the
entire range, because a merge of a right-hand neighbor could complete in
between the time that a request declares its keys and the time that it
evaluates. This could lead to a violation of the mutual exclusion that
the command was expecting to have.

This commit makes these kinds of mistakes impossible to make by putting
the RangeDescriptor behind an interface that only exposes the properties
of a Range that cannot change across a Range's lifetime.

@nvanbenschoten nvanbenschoten requested review from tbg, a team and dt and removed request for a team January 14, 2021 18:30
@cockroach-teamcity
Copy link
Member

This change is Reviewable

The DeclareKeysFunc has always included a full RangeDescriptor, but it
has never been clear which fields in this descriptor are safe to use and
which are not when declaring keys for a request. The concern is that any
property of the RangeDescriptor that is not immutable may change between
the time that a request declares its keys to latch and the time that it
evaluates, so any assumptions based on these mutable fields may not
hold.

The quintessential example of a property of a Range that is not
immutable is its end key. It would be incorrect to declare keys between
a Range's start key and its current end key as a means of latching the
entire range, because a merge of a right-hand neighbor could complete in
between the time that a request declares its keys and the time that it
evaluates. This could lead to a violation of the mutual exclusion that
the command was expecting to have.

This commit makes these kinds of mistakes impossible to make by putting
the RangeDescriptor behind an interface that only exposes the properties
of a Range that cannot change across a Range's lifetime.
Copy link
Member

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

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

@nvanbenschoten
Copy link
Member Author

TFTR!

bors r+

@craig
Copy link
Contributor

craig bot commented Jan 19, 2021

Build succeeded:

@craig craig bot merged commit debeb0b into cockroachdb:master Jan 19, 2021
@nvanbenschoten nvanbenschoten deleted the nvanbenschoten/declareImmutable branch January 28, 2021 01:47
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