Skip to content

Commit

Permalink
domain: sync the access of InfoSyncer.SessionManager (#33924) (#33943)
Browse files Browse the repository at this point in the history
close #33335
  • Loading branch information
ti-srebot authored Sep 15, 2022
1 parent a6f53b2 commit fab67cc
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions domain/infosync/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"path"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"

Expand Down Expand Up @@ -91,12 +92,15 @@ var ErrPrometheusAddrIsNotSet = dbterror.ClassDomain.NewStd(errno.ErrPrometheusA

// InfoSyncer stores server info to etcd when the tidb-server starts and delete when tidb-server shuts down.
type InfoSyncer struct {
etcdCli *clientv3.Client
info *ServerInfo
serverInfoPath string
minStartTS uint64
minStartTSPath string
manager util2.SessionManager
etcdCli *clientv3.Client
info *ServerInfo
serverInfoPath string
minStartTS uint64
minStartTSPath string
managerMu struct {
mu sync.RWMutex
util2.SessionManager
}
session *concurrency.Session
topologySession *concurrency.Session
prometheusAddr string
Expand Down Expand Up @@ -201,12 +205,16 @@ func (is *InfoSyncer) init(ctx context.Context, skipRegisterToDashboard bool) er

// SetSessionManager set the session manager for InfoSyncer.
func (is *InfoSyncer) SetSessionManager(manager util2.SessionManager) {
is.manager = manager
is.managerMu.mu.Lock()
defer is.managerMu.mu.Unlock()
is.managerMu.SessionManager = manager
}

// GetSessionManager get the session manager.
func (is *InfoSyncer) GetSessionManager() util2.SessionManager {
return is.manager
is.managerMu.mu.RLock()
defer is.managerMu.mu.RUnlock()
return is.managerMu.SessionManager
}

func initLabelRuleManager(etcdCli *clientv3.Client) LabelRuleManager {
Expand Down Expand Up @@ -586,11 +594,11 @@ func (is *InfoSyncer) RemoveMinStartTS() {

// ReportMinStartTS reports self server min start timestamp to ETCD.
func (is *InfoSyncer) ReportMinStartTS(store kv.Storage) {
if is.manager == nil {
// Server may not start in time.
sm := is.GetSessionManager()
if sm == nil {
return
}
pl := is.manager.ShowProcessList()
pl := sm.ShowProcessList()

// Calculate the lower limit of the start timestamp to avoid extremely old transaction delaying GC.
currentVer, err := store.CurrentVersion(kv.GlobalTxnScope)
Expand Down

0 comments on commit fab67cc

Please sign in to comment.