Repository navigation
fix(frontend): handle SET TRANSACTION isolation level - #26665
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Request changes for two correctness gaps:
-
handleSetTransactiononly updates the compatibility sysvar map.TxnHandler.createTxnOpUnsafenever readstransaction_isolation, whiletxnClient.newTxnMetainitializes the realTxnMeta.Isolationfrom service-widemoruntime.TxnIsolation. Therefore the new tests prove only that@@transaction_isolationechoes the requested string; a JDBC/ODBC caller can now observe success and the requested value while the next transaction still runs with the old isolation. Please connect the session/next-transaction setting toWithTxnIsolationwhen creating the owned transaction, reject levels MO cannot implement, and add a test that captures the created transaction option/meta rather than only reading the sysvar. -
The AST cannot distinguish
SET TRANSACTION ...fromSET SESSION TRANSACTION ...: both grammar branches produceSetTransaction{Global:false}. This handler consequently makes the unscoped form a persistent session setting. MySQL defines the unscoped form as next-transaction-only, whileSESSIONchanges subsequent session transactions. Please preserve the scope in the AST and test that an unscoped override is consumed once and then falls back to the session default.
Q1/Q2: the current success paths update/report state, but neither reaches the real transaction owner; there is no generation-scoped next-transaction state to consume. Q3: no cleanup/lifecycle regression found in the added handler itself.
Validation: focused frontend tests passed 10x; the failure is a missing semantic assertion, not test instability.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed exact head d03c459. Two merge-blocking correctness issues remain:
-
SetTransaction is classified as a parameter-modification statement that must finish the active transaction. The normal frontend finish path therefore commits the whole existing transaction on a successful SET and rolls it back on an invalid SET. For example, BEGIN; INSERT; SET SESSION TRANSACTION ISOLATION LEVEL ...; ROLLBACK can commit at SET, although SESSION scope inside an active transaction must affect only future transactions. An unscoped SET TRANSACTION rejected inside an active transaction can likewise roll back unrelated prior work. The handler-only tests bypass this lifecycle. Please keep SET TRANSACTION from implicitly committing/rolling back the active transaction and add end-to-end transaction-state counterexamples. MySQL reference: https://dev.mysql.com/doc/refman/8.4/en/set-transaction.html
-
GLOBAL alias persistence is split. Validation accepts transaction_isolation and tx_isolation, but the global update stores only the supplied name; new sessions seed the real TxnHandler isolation only from canonical transaction_isolation. SET GLOBAL tx_isolation='READ-COMMITTED' can therefore update the alias/sysvar view while newly created sessions still execute with the stale canonical isolation. Canonicalize alias writes (and reads) and cover new-session behavior through the actual TxnMeta.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed exact head 628959c1ede68c363981124bfa786e8d3a5865c2. The previous transaction-boundary and canonical-alias blockers are fixed, and the focused frontend/parser tests pass. One correctness blocker remains:
SET TRANSACTION access characteristics are parsed but silently ignored. handleSetTransaction skips every !characteristic.IsLevel item and returns success when no isolation item was found, so SET SESSION TRANSACTION READ ONLY returns OK while storing no read-only state and applying no transaction option; the next transaction is still writable. The BVT/unit tests currently codify that false-success behavior as “syntax compatibility”. Applications can therefore believe a read-only boundary was established when it was not.
Please either implement access mode across the same NEXT/SESSION/GLOBAL state model and apply txnclient.WithTxnReadyOnly() (including READ WRITE reset, one-shot NEXT consumption, active-transaction boundaries, and TxnMeta/write-rejection tests), or fail closed with NotSupported until the behavior is complete. Please also validate duplicate/conflicting characteristics rather than silently accepting a last-wins/no-op list.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Request changes: the new isolation plumbing still has correctness and upgrade blockers.\n\n1. Scope is not closed across equivalent syntaxes. SET SESSION transaction_isolation still takes the generic SetVar path and commits an active user transaction. Bare SET @@transaction_isolation is parsed as SESSION rather than NEXT. Also, SET GLOBAL TRANSACTION creates a frontend temporary txn which consumes a pending NEXT isolation, despite GLOBAL being required to leave existing sessions unaffected. I reproduced all three state transitions.\n\n2. Upgrade availability regression: previous versions accepted and persisted tx_isolation=READ-UNCOMMITTED/SERIALIZABLE. This change reads those valid legacy catalog values, then InitSystemVariables rejects them through txnIsolationFromSystemValue, so new sessions for that account cannot initialize after upgrade. New writes may fail closed, but legacy rows need migration-safe normalization/fallback. Canonical-only writes also leave a rolling-upgrade old node observing the stale tx_isolation row.\n\n3. SET transaction_isolation=DEFAULT uses the static enum default (REPEATABLE-READ), not the service/account global default. On an RC-configured service, a session initialized as RC is changed to RR by DEFAULT; the actual TxnMeta follows the wrong value.\n\n4. The active-NEXT rejection is returned as generic InvalidInput (1105/HY000), whereas MySQL/JDBC compatibility requires ER_CANT_CHANGE_TX_CHARACTERISTICS (1568/25001).\n\nPlease model transaction-characteristic scope centrally at semantic transaction boundaries, and add counterexample tests for these sequences before updating the PR.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep-reviewed exact head 9e80ee7.
[P1] A SESSION isolation assignment must clear a pending NEXT-transaction override.
TxnHandler.setSessionTxnIsolation updates only sessionTxnIsolation and hasSessionTxnIsolation (pkg/frontend/txn.go:357-362). It leaves hasNextTxnIsolation set, while txnIsolationUnsafe gives NEXT precedence (pkg/frontend/txn.go:379-389). Consequently:
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
START TRANSACTION;
still starts the first transaction as RC and consumes the stale NEXT override. The same defect is reachable through bare SET transaction_isolation and SET @@SESSION.transaction_isolation.
MySQL explicitly specifies that a SESSION transaction_isolation assignment between transactions overrides any preceding next-transaction assignment: https://dev.mysql.com/doc/refman/8.4/en/server-system-variables.html#sysvar_transaction_isolation
I added a minimal exact-head state-machine counterexample locally: set NEXT=RC, then SESSION=SI, then call txnIsolationUnsafe(true). It fails because the handler returns RC with consumeNext=true instead of SI with consumeNext=false. Clear the pending NEXT generation when applying SESSION scope and add regressions for SET SESSION TRANSACTION plus both SESSION sysvar spellings.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep-reviewed exact head 5298e821d531d68e7728dfc43df3ff5858c975e6. The stale NEXT override and all previously reported single-assignment scope/default/upgrade gaps are fixed. One transaction-boundary blocker remains:
[P1] Mixed SET assignments bypass the transaction-characteristic preservation path and can roll back an existing user transaction.
isTransactionCharacteristicStatement returns true only when every SetVar assignment is an isolation assignment (pkg/frontend/txn.go). Therefore this valid sequence:
BEGIN;
-- any prior DML
SET @@transaction_isolation = 'READ-COMMITTED', @probe = 1;correctly raises ER_CANT_CHANGE_TX_CHARACTERISTICS (1568), but needToFinishTransactionAtStatementEnd then falls back to NeedToBeCommittedInActiveTransaction(SetVar). The error cleanup takes RollbackUnsafe1, discards the whole pre-existing transaction, and the client can no longer decide to COMMIT or ROLLBACK its prior work. The same classification problem affects successful mixed SESSION-isolation assignments by allowing generic SET lifecycle rules to finish the existing transaction.
I reproduced this on the exact head by adding the mixed statement to TestSetTransactionDoesNotFinishExistingTransaction: after the expected 1568, handler.InActiveTxn() is false and the test fails. Please classify transaction isolation assignments independently of unrelated assignments (or otherwise preserve an active transaction for the whole mixed SET) and add both rejected NEXT and successful SESSION mixed-assignment counterexamples.
Validation of the unaffected paths: focused isolation/boundary tests passed 13x each under race, the full frontend package passed under race, frontend/parser/moerr package tests passed, and the latest-main merge tree is clean.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep-reviewed exact head a0bc85b3830a5eaef212b88eed2bbe1ecc3f6639. The latest mixed-SET fix closes the remaining transaction-boundary blocker: any transaction-isolation assignment now preserves an already active user transaction, including rejected NEXT and successful SESSION statements mixed with unrelated assignments, while statement-owned temporary transactions are still finalized.
I also rechecked scope/default semantics, canonical transaction_isolation / legacy tx_isolation compatibility, rolling-upgrade catalog normalization, one-shot NEXT consumption and failure retention, unsupported access-mode fail-closed behavior, commit timestamp propagation, parser/AST construction, and Q1-Q3 lifecycle paths. I found no remaining correctness, compatibility, concurrency, resource-lifecycle, or performance blocker.
Validation on this exact head: focused transaction-boundary test 100x under -race; isolation/meta/global/legacy/commit-TS tests 100x under -race; full pkg/frontend under -race; parser/tree/moerr tests; and build/vet for all affected production packages. All passed.
Merge Queue Status
This pull request spent 31 seconds in the queue, including 4 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #26648
What this PR does / why we need it:
fix(frontend): handle SET TRANSACTION isolation level