Skip to content

Add ROLLBACK to allowCrossShardTransactions to clear vtgate reserved connection state#3785

Draft
aparajon wants to merge 1 commit intomasterfrom
armand/cross-shard-aftercompletion
Draft

Add ROLLBACK to allowCrossShardTransactions to clear vtgate reserved connection state#3785
aparajon wants to merge 1 commit intomasterfrom
armand/cross-shard-aftercompletion

Conversation

@aparajon
Copy link
Copy Markdown
Collaborator

@aparajon aparajon commented Apr 18, 2026

Summary

  • After allowCrossShardTransactions() commits, send SET transaction_mode = 'unspecified' then ROLLBACK in afterCompletion to clean up vtgate session state
  • SET UNSPECIFIED resets the session variable so MULTI doesn't leak to the pool
  • ROLLBACK clears vtgate's reserved connection stale shard sessions (Bug Report: enabling MySQL safe-updates is incompatible with transaction_mode=SINGLE vitessio/vitess#11616) so subsequent queries don't fail with "multi-db transaction attempted"
  • Both are safe post-commit — ROLLBACK is a data no-op that only affects vtgate session state
  • Updates cross-shard tests to use hasCause helper for cleaner exception assertions

Context

SET transaction_mode triggers vtgate's NeedsReservedConn(), which retains shard sessions across COMMIT. Without ROLLBACK, pooled connections carry stale shard sessions that cause spurious "multi-db transaction attempted" errors on subsequent single-shard operations.

🤖 Generated with Claude Code

… connection state

SET transaction_mode triggers vtgate's NeedsReservedConn(), which
retains stale shard sessions across COMMIT (vitessio/vitess#11616).
Without cleanup, subsequent queries on the same pooled connection fail
with "multi-db transaction attempted" even for single-shard operations.

The afterCompletion handler now sends SET UNSPECIFIED (resets the session
variable) then ROLLBACK (clears the reserved connection state). Both are
safe post-commit — ROLLBACK is a data no-op that only affects vtgate
session state.

Also updates cross-shard tests to use hasCause helper for asserting
CrossShardTransactionException in the cause chain.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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.

1 participant