Skip to content

kv: don't consult ReadTimestamp in Transaction.LastActive#117119

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
nvb:nvanbenschoten/lastActiveSynTs
Jan 9, 2024
Merged

kv: don't consult ReadTimestamp in Transaction.LastActive#117119
craig[bot] merged 1 commit intocockroachdb:masterfrom
nvb:nvanbenschoten/lastActiveSynTs

Conversation

@nvb
Copy link
Copy Markdown
Contributor

@nvb nvb commented Dec 27, 2023

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
@nvb nvb requested a review from arulajmani December 27, 2023 19:04
@nvb nvb requested a review from a team as a code owner December 27, 2023 19:04
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

@nvb nvb 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
Copy Markdown
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 😅

@nvb
Copy link
Copy Markdown
Contributor Author

nvb commented Jan 9, 2024

TFTR!

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jan 9, 2024

Build succeeded:

@craig craig bot merged commit 8793a26 into cockroachdb:master Jan 9, 2024
@nvb nvb 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