Skip to content

Commit

Permalink
session: turn the transaction to pessimistic mode when retrying (#38130
Browse files Browse the repository at this point in the history
…) (#45114)
  • Loading branch information
winoros authored Jul 3, 2023
1 parent 2dd186b commit 3eaac08
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -3160,13 +3160,16 @@ func (s *session) PrepareTxnCtx(ctx context.Context) error {
}

txnMode := ast.Optimistic
if !s.sessionVars.IsAutocommit() || s.sessionVars.RetryInfo.Retrying ||
config.GetGlobalConfig().PessimisticTxn.PessimisticAutoCommit.Load() {
if !s.sessionVars.IsAutocommit() || config.GetGlobalConfig().PessimisticTxn.PessimisticAutoCommit.Load() {
if s.sessionVars.TxnMode == ast.Pessimistic {
txnMode = ast.Pessimistic
}
}

if s.sessionVars.RetryInfo.Retrying {
txnMode = ast.Pessimistic
}

return sessiontxn.GetTxnManager(s).EnterNewTxn(ctx, &sessiontxn.EnterNewTxnRequest{
Type: sessiontxn.EnterNewTxnBeforeStmt,
TxnMode: txnMode,
Expand Down

0 comments on commit 3eaac08

Please sign in to comment.