Skip to content

Commit

Permalink
domain: splite handleDDLEvent into new thread (#53734) (#55275)
Browse files Browse the repository at this point in the history
ref #53744
  • Loading branch information
ti-chi-bot authored Aug 12, 2024
1 parent aa09937 commit ce5bdfe
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,7 @@ func (do *Domain) UpdateTableStatsLoop(ctx, initStatsCtx sessionctx.Context) err
do.wg.Run(func() { do.updateStatsWorker(ctx, owner) })
do.wg.Run(func() { do.autoAnalyzeWorker(owner) })
do.wg.Run(func() { do.gcAnalyzeHistory(owner) })
do.wg.Run(do.handleDDLEvent)
return nil
}

Expand Down Expand Up @@ -2016,6 +2017,24 @@ func (do *Domain) syncIndexUsageWorker(owner owner.Manager) {
}
}

func (do *Domain) handleDDLEvent() {
logutil.BgLogger().Info("handleDDLEvent started.")
defer util.Recover(metrics.LabelDomain, "handleDDLEvent", nil, false)
statsHandle := do.StatsHandle()
for {
select {
case <-do.exit:
return
// This channel is sent only by ddl owner.
case t := <-statsHandle.DDLEventCh():
err := statsHandle.HandleDDLEvent(t)
if err != nil {
logutil.BgLogger().Error("handle ddl event failed", zap.String("event", t.String()), zap.Error(err))
}
}
}
}

func (do *Domain) updateStatsWorker(ctx sessionctx.Context, owner owner.Manager) {
defer util.Recover(metrics.LabelDomain, "updateStatsWorker", nil, false)
lease := do.statsLease
Expand Down Expand Up @@ -2045,12 +2064,6 @@ func (do *Domain) updateStatsWorker(ctx sessionctx.Context, owner owner.Manager)
statsHandle.FlushStats()
owner.Cancel()
return
// This channel is sent only by ddl owner.
case t := <-statsHandle.DDLEventCh():
err := statsHandle.HandleDDLEvent(t)
if err != nil {
logutil.BgLogger().Error("handle ddl event failed", zap.String("event", t.String()), zap.Error(err))
}
case <-deltaUpdateTicker.C:
err := statsHandle.DumpStatsDeltaToKV(handle.DumpDelta)
if err != nil {
Expand Down

0 comments on commit ce5bdfe

Please sign in to comment.