Skip to content

Commit

Permalink
domain: do not start Auto Analyze Worker until statistics initializat…
Browse files Browse the repository at this point in the history
…ion is complete (#52407) (#52512)

close #52346
  • Loading branch information
ti-chi-bot authored Apr 15, 2024
1 parent 7efe4ea commit 0f584f0
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions pkg/domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2271,9 +2271,26 @@ func (do *Domain) UpdateTableStatsLoop(ctx, initStatsCtx sessionctx.Context) err
return nil
}
do.SetStatsUpdating(true)
// The stats updated worker doesn't require the stats initialization to be completed.
// This is because the updated worker's primary responsibilities are to update the change delta and handle DDL operations.
// These tasks do not interfere with or depend on the initialization process.
do.wg.Run(func() { do.updateStatsWorker(ctx, owner) }, "updateStatsWorker")
do.wg.Run(func() { do.autoAnalyzeWorker(owner) }, "autoAnalyzeWorker")
do.wg.Run(func() { do.gcAnalyzeHistory(owner) }, "gcAnalyzeHistory")
// Wait for the stats worker to finish the initialization.
// Otherwise, we may start the auto analyze worker before the stats cache is initialized.
do.wg.Run(
func() {
<-do.StatsHandle().InitStatsDone
do.autoAnalyzeWorker(owner)
},
"autoAnalyzeWorker",
)
do.wg.Run(
func() {
<-do.StatsHandle().InitStatsDone
do.gcAnalyzeHistory(owner)
},
"gcAnalyzeHistory",
)
return nil
}

Expand Down

0 comments on commit 0f584f0

Please sign in to comment.