From 1a89decdb192cbdce6a7b0020d71128bc964d30f Mon Sep 17 00:00:00 2001 From: cfzjywxk Date: Sun, 5 Jun 2022 12:24:28 +0800 Subject: [PATCH] txn: skip the transaction start_ts used by analyze calculating the gc safepoint (#35144) --- server/server.go | 6 +++++- session/session.go | 12 ++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/server/server.go b/server/server.go index 3221b6edc2acb..90b4a7e27101b 100644 --- a/server/server.go +++ b/server/server.go @@ -833,8 +833,12 @@ func (s *Server) GetInternalSessionStartTSList() []uint64 { s.sessionMapMutex.Lock() defer s.sessionMapMutex.Unlock() tsList := make([]uint64, 0, len(s.internalSessions)) + analyzeProcID := util.GetAutoAnalyzeProcID(s.ServerID) for se := range s.internalSessions { - if ts := session.GetStartTSFromSession(se); ts != 0 { + if ts, processInfoID := session.GetStartTSFromSession(se); ts != 0 { + if processInfoID == analyzeProcID { + continue + } tsList = append(tsList, ts) } } diff --git a/session/session.go b/session/session.go index decee805527d9..a43873e26a2fd 100644 --- a/session/session.go +++ b/session/session.go @@ -3230,12 +3230,16 @@ func (s *session) ShowProcess() *util.ProcessInfo { } // GetStartTSFromSession returns the startTS in the session `se` -func GetStartTSFromSession(se interface{}) uint64 { - var startTS uint64 +func GetStartTSFromSession(se interface{}) (uint64, uint64) { + var startTS, processInfoID uint64 tmp, ok := se.(*session) if !ok { logutil.BgLogger().Error("GetStartTSFromSession failed, can't transform to session struct") - return 0 + return 0, 0 + } + processInfo := tmp.ShowProcess() + if processInfo != nil { + processInfoID = processInfo.ID } txnInfo := tmp.TxnInfo() if txnInfo != nil { @@ -3246,7 +3250,7 @@ func GetStartTSFromSession(se interface{}) uint64 { "GetStartTSFromSession getting startTS of internal session", zap.Uint64("startTS", startTS), zap.Time("start time", oracle.GetTimeFromTS(startTS))) - return startTS + return startTS, processInfoID } // logStmt logs some crucial SQL including: CREATE USER/GRANT PRIVILEGE/CHANGE PASSWORD/DDL etc and normal SQL