Skip to content

Commit

Permalink
domain: use util.WaitGroupWrapper insteal of sync.WaitGroup (#33637)
Browse files Browse the repository at this point in the history
ref #31716
  • Loading branch information
hawkingrei committed Apr 1, 2022
1 parent db852db commit 9d44656
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
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

0 comments on commit 9d44656

Please sign in to comment.