release-25.4: sql: step read seq on rollback #160476
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.
Backport 1/1 commits from #160346 on behalf of @jeffswenson.
The conn executor creates transactions with "stepped" read sequences. The purpose of this behavior is to prevent a statement from reading its own writes, which is required by postgres semantics. When a savepoint is rolled back, it creates a [start_savepoint_seq, end_savepoint_seq) span of reverted sequences. The txn middleware validates the transaction's read sequence number to ensure it's not inside a reverted span. If the read sequence is inside a reverted span, the transaction requests return assertion failures and are not sent to the KV layer.
This validation means that if a transaction has its read timestamp inside a reverted span when it attempts to roll back the transaction, the RPCs to clean up the transaction are never sent. The transaction is orphaned and is cleaned up automatically, but it leaves the locks in place for a few seconds. Since the txn is cleaned up eventually, the conn executor logs an error instead of poisoning the session.
Fixes: #156507
Fixes: #135118
Fixes: #159594
Release note (bug fix): Fixed a bug that caused rolling back a transaction that just rolled back a savepoint to block transactions touching the same rows for five seconds.
Release justification: Fixes a bug that has been escalated by customers and causes difficult to track down performance issues.