Skip to content

Commit

Permalink
testkit: fix data race in GetInternalSessionStartTSList (#54403)
Browse files Browse the repository at this point in the history
close #54374, close #54395
  • Loading branch information
YangKeao authored Jul 3, 2024
1 parent ef53d61 commit 959c8a6
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions pkg/testkit/mocksessionmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,23 @@ func (msm *MockSessionManager) GetInternalSessionStartTSList() []uint64 {
defer msm.mu.Unlock()
ret := make([]uint64, 0, len(msm.internalSessions))
for internalSess := range msm.internalSessions {
se := internalSess.(sessionctx.Context)
txn, err := se.Txn(false)
if err != nil {
// Ref the implementation of `GetInternalSessionStartTSList` on the real session manager. The `TxnInfo` is more
// accurate, because if a session is pending, the `StartTS` in `sessVars.TxnCtx` will not be updated. For example,
// if there is not DDL for a long time, the minimal internal session start ts will not have any progress.
if se, ok := internalSess.(interface{ TxnInfo() *txninfo.TxnInfo }); ok {
txn := se.TxnInfo()
if txn != nil {
ret = append(ret, txn.StartTS)
}
continue
}
if txn.Valid() {
ret = append(ret, txn.StartTS())
}

se := internalSess.(sessionctx.Context)
sessVars := se.GetSessionVars()
sessVars.TxnCtxMu.Lock()
startTS := sessVars.TxnCtx.StartTS
sessVars.TxnCtxMu.Unlock()
ret = append(ret, startTS)
}
return ret
}
Expand Down

0 comments on commit 959c8a6

Please sign in to comment.