From 0b6571aa88d53b6ef760f521db2001a74e23cc4d Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Fri, 30 Sep 2022 11:59:45 +0800 Subject: [PATCH] session: turn the transaction to pessimistic mode when retrying (#38130) close pingcap/tidb#38136 --- session/session.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/session/session.go b/session/session.go index 637c971b03609..25a3f05441352 100644 --- a/session/session.go +++ b/session/session.go @@ -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,