From b36dc728f1c3973c2314cbb6f4dda26970a46987 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Tue, 12 Nov 2024 00:11:09 +0800 Subject: [PATCH] domain: set right order to compaign stats owner (#57200) (#57236) close pingcap/tidb#57199 --- pkg/domain/domain.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pkg/domain/domain.go b/pkg/domain/domain.go index 3e395ceac40c2..cfbfaa4add87c 100644 --- a/pkg/domain/domain.go +++ b/pkg/domain/domain.go @@ -2006,6 +2006,11 @@ func (do *Domain) LoadBindInfoLoop(ctxForHandle sessionctx.Context, ctxForEvolve } owner := do.newOwnerManager(bindinfo.Prompt, bindinfo.OwnerKey) + err = owner.CampaignOwner() + if err != nil { + logutil.BgLogger().Warn("campaign owner failed", zap.Error(err)) + return err + } do.globalBindHandleWorkerLoop(owner) return nil } @@ -2330,6 +2335,13 @@ func (do *Domain) UpdateTableStatsLoop(ctx, initStatsCtx sessionctx.Context) err variable.DisableStatsOwner = do.disableStatsOwner do.statsOwner = do.newOwnerManager(handle.StatsPrompt, handle.StatsOwnerKey) do.statsOwner.SetListener(owner.NewListenersWrapper(statsHandle, do.ddlNotifier)) + if config.GetGlobalConfig().Instance.TiDBEnableStatsOwner.Load() { + err := do.statsOwner.CampaignOwner() + if err != nil { + logutil.BgLogger().Warn("campaign owner failed", zap.Error(err)) + return err + } + } do.wg.Run(func() { do.indexUsageWorker() }, "indexUsageWorker") @@ -2438,13 +2450,6 @@ func (do *Domain) newOwnerManager(prompt, ownerKey string) owner.Manager { } else { statsOwner = owner.NewOwnerManager(context.Background(), do.etcdClient, prompt, id, ownerKey) } - // TODO: Need to do something when err is not nil. - if ownerKey == handle.StatsOwnerKey && config.GetGlobalConfig().Instance.TiDBEnableStatsOwner.Load() { - err := statsOwner.CampaignOwner() - if err != nil { - logutil.BgLogger().Warn("campaign owner failed", zap.Error(err)) - } - } return statsOwner }