From d0c3c3322525ab8f562591da1aa4025715fa45d0 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Thu, 7 Nov 2024 18:43:13 +0800 Subject: [PATCH] domain: set right order to compaign stats owner (#57200) 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 0e80d904db8e2..d8e76396de26f 100644 --- a/pkg/domain/domain.go +++ b/pkg/domain/domain.go @@ -2063,6 +2063,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 } @@ -2387,6 +2392,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") @@ -2495,13 +2507,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 }