-
Notifications
You must be signed in to change notification settings - Fork 278
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
fix HCLRevision mismatch on zero logical clock #2122
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
github-actions
bot
added
area/datastore
Affects the storage system
area/tooling
Affects the dev or user toolchain (e.g. tests, ci, build tools)
labels
Nov 6, 2024
vroldanbet
force-pushed
the
hcl-zero-fix
branch
3 times, most recently
from
November 6, 2024 17:41
a8a0b39
to
da8f405
Compare
While developing the test-case for `EmitImmediatelyStrategy` with CRDB, I detected something I wasn't expecting: when comparing the revision out of the datastore write, and what came out of Watch API, the revisions were different. We use `SHOW COMMIT TIMESTAMP` to retrieve a CRDB [transaction timestamp] (cockroachdb/cockroach#80848). The value coming out of the `update` field in change streams had the same value, but the difference was the notation: one included the logical clock, the other didn't, but logical clocks were the same (zero): - revision generated out of the transaction in `readTransactionCommitRev` uses `NewForHLC(hlcNow)`, which takes a `Decimal`. This in turn calls `decimal.String()`, which returns a number stripped out of the decimal part if it's zero. - revision obtained out of the changefeeds uses `revisions.HLCRevisionFromString (details.Updated)`, and `details.Updated` always comes with the decimal part, even when it's zero Both timestamps were the same, but had a different string representation, and led to a different `HCLRevision` logical lock, hence `.Equal()` method failing.
vroldanbet
force-pushed
the
hcl-zero-fix
branch
from
November 6, 2024 18:41
da8f405
to
b5ba432
Compare
we don't expect it to be possible to have CRDB generate 4B conflicts
vroldanbet
force-pushed
the
hcl-zero-fix
branch
from
November 6, 2024 18:55
b5ba432
to
fa3c813
Compare
josephschorr
approved these changes
Nov 6, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
area/datastore
Affects the storage system
area/tooling
Affects the dev or user toolchain (e.g. tests, ci, build tools)
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While working on #2120, I detected something I wasn't expecting: when comparing the revision out of the datastore write, and what came out of Watch API, the revisions were different.
We use
SHOW COMMIT TIMESTAMP
to retrieve a CRDB transaction timestamp. The value coming out of theupdate
field in change streams had the same value, but the difference was the notation: one included the logical clock, the other didn't, but logical clocks were the same (zero):readTransactionCommitRev
usesNewForHLC(hlcNow)
, which takes aDecimal
. This in turn callsdecimal.String()
, which returns a number stripped out of the decimal part if it's zero.revisions.HLCRevisionFromString(details.Updated)
, anddetails.Updated
always comes with the decimal part, even when it's zeroBoth timestamps were the same, but had a different string representation, and led to a different
HCLRevision
logical lock, hence.Equal()
method failing.The problem originates in the use of the offset to represent the logical part of the clock. The representation of "zero" wasn't being used consistently, and in some parts of the code the revision was initialized with logical clock of zero, when it needed the offset padding.
HLCRevision
, that is, which only applies to CRDB). This means caches that append the revision to keys will be longer.