From 3eaac086bc4ee659d151645c0538de5d932e8451 Mon Sep 17 00:00:00 2001 From: Yiding Cui Date: Mon, 3 Jul 2023 10:56:13 +0800 Subject: [PATCH] session: turn the transaction to pessimistic mode when retrying (#38130) (#45114) --- 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,