From 6e958a498a2afb36761dee6db09a509eb60f6734 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Thu, 17 Aug 2023 11:27:30 +0800 Subject: [PATCH] domain, tidb-server: stop launching new auto analyze job when shutting down (#41346) (#41392) close pingcap/tidb#41318 --- domain/domain.go | 10 +++++++++- tidb-server/main.go | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/domain/domain.go b/domain/domain.go index fd3a7efab7f68..5bea4755a8194 100644 --- a/domain/domain.go +++ b/domain/domain.go @@ -137,6 +137,8 @@ type Domain struct { sync.Mutex sctxs map[sessionctx.Context]bool } + + stopAutoAnalyze atomicutil.Bool } type mdlCheckTableInfo struct { @@ -904,6 +906,7 @@ func NewDomain(store kv.Storage, ddlLease time.Duration, statsLease time.Duratio }, } + do.stopAutoAnalyze.Store(false) do.SchemaValidator = NewSchemaValidator(ddlLease, do) do.expensiveQueryHandle = expensivequery.NewExpensiveQueryHandle(do.exit) do.memoryUsageAlarmHandle = memoryusagealarm.NewMemoryUsageAlarmHandle(do.exit) @@ -2039,7 +2042,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: @@ -2419,6 +2422,11 @@ func (do *Domain) TTLJobManager() *ttlworker.JobManager { return do.ttlJobManager } +// 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 { diff --git a/tidb-server/main.go b/tidb-server/main.go index 6d2b432a36a9c..d8b830fc9c9a1 100644 --- a/tidb-server/main.go +++ b/tidb-server/main.go @@ -836,6 +836,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)