File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -2288,6 +2288,7 @@ func (do *Domain) UpdateTableStatsLoop(ctx, initStatsCtx sessionctx.Context) err
2288
2288
return nil
2289
2289
}
2290
2290
do .SetStatsUpdating (true )
2291
+ do .wg .Run (do .asyncLoadHistogram , "asyncLoadHistogram" )
2291
2292
// The stats updated worker doesn't require the stats initialization to be completed.
2292
2293
// This is because the updated worker's primary responsibilities are to update the change delta and handle DDL operations.
2293
2294
// These tasks do not interfere with or depend on the initialization process.
@@ -2409,6 +2410,33 @@ func (do *Domain) loadStatsWorker() {
2409
2410
if err != nil {
2410
2411
logutil .BgLogger ().Warn ("update stats info failed" , zap .Error (err ))
2411
2412
}
2413
+ case <- do .exit :
2414
+ return
2415
+ }
2416
+ }
2417
+ }
2418
+
2419
+ func (do * Domain ) asyncLoadHistogram () {
2420
+ defer util .Recover (metrics .LabelDomain , "asyncLoadStats" , nil , false )
2421
+ lease := do .statsLease
2422
+ if lease == 0 {
2423
+ lease = 3 * time .Second
2424
+ }
2425
+ cleanupTicker := time .NewTicker (lease )
2426
+ defer func () {
2427
+ cleanupTicker .Stop ()
2428
+ logutil .BgLogger ().Info ("asyncLoadStats exited." )
2429
+ }()
2430
+ select {
2431
+ case <- do .StatsHandle ().InitStatsDone :
2432
+ case <- do .exit : // It may happen that before initStatsDone, tidb receive Ctrl+C
2433
+ return
2434
+ }
2435
+ statsHandle := do .StatsHandle ()
2436
+ var err error
2437
+ for {
2438
+ select {
2439
+ case <- cleanupTicker .C :
2412
2440
err = statsHandle .LoadNeededHistograms ()
2413
2441
if err != nil {
2414
2442
logutil .BgLogger ().Warn ("load histograms failed" , zap .Error (err ))
You can’t perform that action at this time.
0 commit comments