@@ -2113,6 +2113,18 @@ func (ex *connExecutor) execStmtInOpenStateWithPausablePortal(
21132113 return nil , nil , nil
21142114}
21152115
2116+ func (ex * connExecutor ) stepReadSequence (ctx context.Context ) error {
2117+ prevSteppingMode := ex .state .mu .txn .ConfigureStepping (ctx , kv .SteppingEnabled )
2118+ if prevSteppingMode == kv .SteppingEnabled {
2119+ if err := ex .state .mu .txn .Step (ctx , false /* allowReadTimestampStep */ ); err != nil {
2120+ return err
2121+ }
2122+ } else {
2123+ ex .state .mu .txn .ConfigureStepping (ctx , prevSteppingMode )
2124+ }
2125+ return nil
2126+ }
2127+
21162128// handleAOST gets the AsOfSystemTime clause from the statement, and sets
21172129// the timestamps of the transaction accordingly.
21182130func (ex * connExecutor ) handleAOST (ctx context.Context , stmt tree.Statement ) error {
@@ -2385,13 +2397,8 @@ func (ex *connExecutor) commitSQLTransactionInternal(ctx context.Context) (retEr
23852397 // write-write contention between transactions by inflating the contention
23862398 // footprint of each transaction (i.e. the duration measured in MVCC time that
23872399 // the transaction holds locks).
2388- prevSteppingMode := ex .state .mu .txn .ConfigureStepping (ctx , kv .SteppingEnabled )
2389- if prevSteppingMode == kv .SteppingEnabled {
2390- if err := ex .state .mu .txn .Step (ctx , false /* allowReadTimestampStep */ ); err != nil {
2391- return err
2392- }
2393- } else {
2394- ex .state .mu .txn .ConfigureStepping (ctx , prevSteppingMode )
2400+ if err := ex .stepReadSequence (ctx ); err != nil {
2401+ return err
23952402 }
23962403
23972404 if err := ex .createJobs (ctx ); err != nil {
@@ -2516,7 +2523,14 @@ func (ex *connExecutor) rollbackSQLTransaction(
25162523 isKVTxnOpen = ex .state .mu .txn .IsOpen ()
25172524 }
25182525 if isKVTxnOpen {
2519- if err := ex .state .mu .txn .Rollback (ctx ); err != nil {
2526+ // Step the read sequence before rolling back because the read sequence
2527+ // may be in the span reverted by a savepoint.
2528+ err := ex .stepReadSequence (ctx )
2529+ err = errors .CombineErrors (err , ex .state .mu .txn .Rollback (ctx ))
2530+ if err != nil {
2531+ if buildutil .CrdbTestBuild && errors .IsAssertionFailure (err ) {
2532+ log .Dev .Fatalf (ctx , "txn rollback failed: %+v" , err )
2533+ }
25202534 log .Dev .Warningf (ctx , "txn rollback failed: %s" , err )
25212535 }
25222536 }
0 commit comments