Skip to content

Commit

Permalink
domain, tidb-server: stop launching new auto analyze job when shuttin…
Browse files Browse the repository at this point in the history
…g down (pingcap#41346)

close pingcap#41318
  • Loading branch information
xuyifangreeneyes authored and ghazalfamilyusa committed Feb 15, 2023
1 parent eda4480 commit d649179
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ type Domain struct {
sync.Mutex
sctxs map[sessionctx.Context]bool
}

stopAutoAnalyze atomicutil.Bool
}

type mdlCheckTableInfo struct {
Expand Down Expand Up @@ -960,6 +962,7 @@ func NewDomain(store kv.Storage, ddlLease time.Duration, statsLease time.Duratio
jobsIdsMap: make(map[int64]string),
},
}
do.stopAutoAnalyze.Store(false)
do.wg = util.NewWaitGroupEnhancedWrapper("domain", do.exit, config.GetGlobalConfig().TiDBEnableExitCheck)
do.SchemaValidator = NewSchemaValidator(ddlLease, do)
do.expensiveQueryHandle = expensivequery.NewExpensiveQueryHandle(do.exit)
Expand Down Expand Up @@ -2185,7 +2188,7 @@ func (do *Domain) autoAnalyzeWorker(owner owner.Manager) {
for {
select {
case <-analyzeTicker.C:
if variable.RunAutoAnalyze.Load() && owner.IsOwner() {
if variable.RunAutoAnalyze.Load() && !do.stopAutoAnalyze.Load() && owner.IsOwner() {
statsHandle.HandleAutoAnalyze(do.InfoSchema())
}
case <-do.exit:
Expand Down Expand Up @@ -2565,6 +2568,11 @@ func (do *Domain) TTLJobManager() *ttlworker.JobManager {
return do.ttlJobManager.Load()
}

// StopAutoAnalyze stops (*Domain).autoAnalyzeWorker to launch new auto analyze jobs.
func (do *Domain) StopAutoAnalyze() {
do.stopAutoAnalyze.Store(true)
}

func init() {
initByLDFlagsForGlobalKill()
telemetry.GetDomainInfoSchema = func(ctx sessionctx.Context) infoschema.InfoSchema {
Expand Down
1 change: 1 addition & 0 deletions tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@ func closeDomainAndStorage(storage kv.Storage, dom *domain.Domain) {
}

func cleanup(svr *server.Server, storage kv.Storage, dom *domain.Domain, graceful bool) {
dom.StopAutoAnalyze()
if graceful {
done := make(chan struct{})
svr.GracefulDown(context.Background(), done)
Expand Down

0 comments on commit d649179

Please sign in to comment.