Skip to content

Commit 0f23d83

Browse files
authored
domain: do not start Auto Analyze Worker until statistics initialization is complete (#52407)
close #52346
1 parent 2debbed commit 0f23d83

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

pkg/domain/domain.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,9 +2228,26 @@ func (do *Domain) UpdateTableStatsLoop(ctx, initStatsCtx sessionctx.Context) err
22282228
return nil
22292229
}
22302230
do.SetStatsUpdating(true)
2231+
// The stats updated worker doesn't require the stats initialization to be completed.
2232+
// This is because the updated worker's primary responsibilities are to update the change delta and handle DDL operations.
2233+
// These tasks do not interfere with or depend on the initialization process.
22312234
do.wg.Run(func() { do.updateStatsWorker(ctx, owner) }, "updateStatsWorker")
2232-
do.wg.Run(func() { do.autoAnalyzeWorker(owner) }, "autoAnalyzeWorker")
2233-
do.wg.Run(func() { do.analyzeJobsCleanupWorker(owner) }, "analyzeJobsCleanupWorker")
2235+
// Wait for the stats worker to finish the initialization.
2236+
// Otherwise, we may start the auto analyze worker before the stats cache is initialized.
2237+
do.wg.Run(
2238+
func() {
2239+
<-do.StatsHandle().InitStatsDone
2240+
do.autoAnalyzeWorker(owner)
2241+
},
2242+
"autoAnalyzeWorker",
2243+
)
2244+
do.wg.Run(
2245+
func() {
2246+
<-do.StatsHandle().InitStatsDone
2247+
do.analyzeJobsCleanupWorker(owner)
2248+
},
2249+
"analyzeJobsCleanupWorker",
2250+
)
22342251
return nil
22352252
}
22362253

0 commit comments

Comments
 (0)