fix HCLRevision mismatch on zero logical clock #2122
Merged
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.