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: don't consult ReadTimestamp in Transaction.LastActive #117119

Merged

Conversation

nvanbenschoten
Copy link
Member

Informs #101938.

Without the synthetic timestamp bit, we don't know for sure whether the transaction's ReadTimestamp is a ClockTimestamp or not. To avoid comparing a future-time MVCC timestamp against a clock timestamp for purposes of detecting transaction liveness, we stop consulting the ReadTimestamp. This was always an unproven optimization anyway, so it's safe to remove.

Release note: None

Informs cockroachdb#101938.

Without the synthetic timestamp bit, we don't know for sure whether the
transaction's ReadTimestamp is a ClockTimestamp or not. To avoid
comparing a future-time MVCC timestamp against a clock timestamp for
purposes of detecting transaction liveness, we stop consulting the
ReadTimestamp. This was always an unproven optimization anyway, so it's
safe to remove.

Release note: None
@nvanbenschoten nvanbenschoten requested a review from a team as a code owner December 27, 2023 19:04
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 3 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @nvanbenschoten)


pkg/roachpb/data.go line 1000 at r1 (raw file):

// LastActive returns the last timestamp at which client activity definitely
// occurred, i.e. the maximum of MinTimestamp and LastHeartbeat.

Why switch from ReadTimestamp to MinTimestamp here?

IIUC, MinTimestamp is the first ReadTimestamp for a transaction. From then on, the ReadTimestamp may advance if the transaction successfully refreshes -- don't we want to treat this advanced timestamp as last active, as there was activity at that timestamp which prompted the refresh?

Copy link
Member Author

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

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


pkg/roachpb/data.go line 1000 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Why switch from ReadTimestamp to MinTimestamp here?

IIUC, MinTimestamp is the first ReadTimestamp for a transaction. From then on, the ReadTimestamp may advance if the transaction successfully refreshes -- don't we want to treat this advanced timestamp as last active, as there was activity at that timestamp which prompted the refresh?

We want LastActive to have a relationship with real-time so that we can compare it with a clock reading and determine how long it has been since the transaction was last active. If we can't check whether the ReadTimestamp is synthetic then we don't know whether it's a future-time timestamp or not, so we stop trying.

I don't think this ever actually mattered anyway, as this is only used when pushing a transaction to see whether it has expired, in which case the LastHeartbeat is the important part. ReadTimestamp isn't even advanced in the txn record on txn heartbeats. So I think this was just an premature optimization from 8c0b2ec, as part of the much larger refactor in #42236.

@arulajmani arulajmani self-requested a review January 9, 2024 20:43
Copy link
Collaborator

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

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

Reviewable isn't letting me type comments for some reason, but your explanation makes sense. My bad on not reading the commit message properly 😅

@nvanbenschoten
Copy link
Member Author

TFTR!

bors r+

@craig
Copy link
Contributor

craig bot commented Jan 9, 2024

Build succeeded:

@craig craig bot merged commit 8793a26 into cockroachdb:master Jan 9, 2024
9 checks passed
@nvanbenschoten nvanbenschoten deleted the nvanbenschoten/lastActiveSynTs branch January 9, 2024 22: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