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: use util.WaitGroupWrapper insteal of sync.WaitGroup #33637

Merged
merged 6 commits into from
Apr 1, 2022
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
18 changes: 5 additions & 13 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type Domain struct {
sysVarCache sysVarCache // replaces GlobalVariableCache
slowQuery *topNSlowQueries
expensiveQueryHandle *expensivequery.Handle
wg sync.WaitGroup
wg util.WaitGroupWrapper
statsUpdating atomicutil.Int32
cancel context.CancelFunc
indexUsageSyncLease time.Duration
Expand Down Expand Up @@ -1298,8 +1298,7 @@ func (do *Domain) UpdateTableStatsLoop(ctx sessionctx.Context) error {
do.ddl.RegisterStatsHandle(statsHandle)
// Negative stats lease indicates that it is in test, it does not need update.
if do.statsLease >= 0 {
do.wg.Add(1)
go do.loadStatsWorker()
do.wg.Run(do.loadStatsWorker)
}
owner := do.newOwnerManager(handle.StatsPrompt, handle.StatsOwnerKey)
if do.indexUsageSyncLease > 0 {
Expand All @@ -1309,15 +1308,12 @@ func (do *Domain) UpdateTableStatsLoop(ctx sessionctx.Context) error {
if do.statsLease <= 0 {
return nil
}
do.wg.Add(1)
do.SetStatsUpdating(true)
go do.updateStatsWorker(ctx, owner)
do.wg.Run(func() { do.updateStatsWorker(ctx, owner) })
if RunAutoAnalyze {
do.wg.Add(1)
go do.autoAnalyzeWorker(owner)
do.wg.Run(func() { do.autoAnalyzeWorker(owner) })
}
do.wg.Add(1)
go do.gcAnalyzeHistory(owner)
do.wg.Run(func() { do.gcAnalyzeHistory(owner) })
return nil
}

Expand Down Expand Up @@ -1356,7 +1352,6 @@ func (do *Domain) loadStatsWorker() {
loadTicker := time.NewTicker(lease)
defer func() {
loadTicker.Stop()
do.wg.Done()
logutil.BgLogger().Info("loadStatsWorker exited.")
}()
statsHandle := do.StatsHandle()
Expand Down Expand Up @@ -1434,7 +1429,6 @@ func (do *Domain) updateStatsWorker(ctx sessionctx.Context, owner owner.Manager)
gcStatsTicker.Stop()
deltaUpdateTicker.Stop()
do.SetStatsUpdating(false)
do.wg.Done()
logutil.BgLogger().Info("updateStatsWorker exited.")
}()
for {
Expand Down Expand Up @@ -1492,7 +1486,6 @@ func (do *Domain) autoAnalyzeWorker(owner owner.Manager) {
analyzeTicker := time.NewTicker(do.statsLease)
defer func() {
analyzeTicker.Stop()
do.wg.Done()
logutil.BgLogger().Info("autoAnalyzeWorker exited.")
}()
for {
Expand All @@ -1514,7 +1507,6 @@ func (do *Domain) gcAnalyzeHistory(owner owner.Manager) {
gcTicker := time.NewTicker(gcInterval)
defer func() {
gcTicker.Stop()
do.wg.Done()
logutil.BgLogger().Info("gcAnalyzeHistory exited.")
}()
for {
Expand Down
3 changes: 2 additions & 1 deletion statistics/handle/handle_hist.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/statistics"
"github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/sqlexec"
"go.uber.org/zap"
Expand Down Expand Up @@ -136,7 +137,7 @@ type StatsReaderContext struct {
}

// SubLoadWorker loads hist data for each column
func (h *Handle) SubLoadWorker(ctx sessionctx.Context, exit chan struct{}, exitWg *sync.WaitGroup) {
func (h *Handle) SubLoadWorker(ctx sessionctx.Context, exit chan struct{}, exitWg *util.WaitGroupWrapper) {
readerCtx := &StatsReaderContext{}
defer func() {
exitWg.Done()
Expand Down