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: move async load stats into single goroutine (#58302) #59142

Open
wants to merge 1 commit into
base: release-7.5
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions pkg/domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2288,6 +2288,7 @@ func (do *Domain) UpdateTableStatsLoop(ctx, initStatsCtx sessionctx.Context) err
return nil
}
do.SetStatsUpdating(true)
do.wg.Run(do.asyncLoadHistogram, "asyncLoadHistogram")
// 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.
Expand Down Expand Up @@ -2409,7 +2410,38 @@ func (do *Domain) loadStatsWorker() {
if err != nil {
logutil.BgLogger().Warn("update stats info failed", zap.Error(err))
}
<<<<<<< HEAD
err = statsHandle.LoadNeededHistograms()
=======
case <-do.exit:
return
}
}
}

func (do *Domain) asyncLoadHistogram() {
defer util.Recover(metrics.LabelDomain, "asyncLoadStats", nil, false)
lease := do.statsLease
if lease == 0 {
lease = 3 * time.Second
}
cleanupTicker := time.NewTicker(lease)
defer func() {
cleanupTicker.Stop()
logutil.BgLogger().Info("asyncLoadStats exited.")
}()
select {
case <-do.StatsHandle().InitStatsDone:
case <-do.exit: // It may happen that before initStatsDone, tidb receive Ctrl+C
return
}
statsHandle := do.StatsHandle()
var err error
for {
select {
case <-cleanupTicker.C:
err = statsHandle.LoadNeededHistograms(do.InfoSchema())
>>>>>>> 0be1983389d (domain: move async load stats into single goroutine (#58302))
if err != nil {
logutil.BgLogger().Warn("load histograms failed", zap.Error(err))
}
Expand Down