Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

domain, tidb-server: stop launching new auto analyze job when shutting down (#41346) #41392

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ type Domain struct {
sync.Mutex
sctxs map[sessionctx.Context]bool
}

stopAutoAnalyze atomicutil.Bool
}

type mdlCheckTableInfo struct {
Expand Down Expand Up @@ -898,6 +900,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)
Expand Down Expand Up @@ -2025,7 +2028,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 @@ -2405,6 +2408,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 {
Expand Down
1 change: 1 addition & 0 deletions tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,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