From 18ecfba603c8d52cd8cbfbd5eb077bb9f5d49598 Mon Sep 17 00:00:00 2001 From: tiancaiamao Date: Tue, 5 Sep 2023 01:11:11 +0800 Subject: [PATCH] autoid_service,owner: change autoid service's etcd lease to 10s (#46455) close pingcap/tidb#46454 --- autoid_service/autoid.go | 3 ++- owner/manager.go | 10 +++++++--- owner/mock.go | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/autoid_service/autoid.go b/autoid_service/autoid.go index 4ecd41d1ecfed..9f5a34e1385b4 100644 --- a/autoid_service/autoid.go +++ b/autoid_service/autoid.go @@ -306,7 +306,8 @@ func newWithCli(selfAddr string, cli *clientv3.Client, store kv.Storage) *Servic zap.String("addr", selfAddr), zap.String("category", "autoid service")) }) - err := l.CampaignOwner() + // 10 means that autoid service's etcd lease is 10s. + err := l.CampaignOwner(10) if err != nil { panic(err) } diff --git a/owner/manager.go b/owner/manager.go index dc9c7058cd2d6..f983b601f4451 100644 --- a/owner/manager.go +++ b/owner/manager.go @@ -53,7 +53,7 @@ type Manager interface { // SetOwnerOpValue updates the owner op value. SetOwnerOpValue(ctx context.Context, op OpType) error // CampaignOwner campaigns the owner. - CampaignOwner() error + CampaignOwner(...int) error // ResignOwner lets the owner start a new election. ResignOwner(ctx context.Context) error // Cancel cancels this etcd ownerManager. @@ -173,10 +173,14 @@ func setManagerSessionTTL() error { } // CampaignOwner implements Manager.CampaignOwner interface. -func (m *ownerManager) CampaignOwner() error { +func (m *ownerManager) CampaignOwner(withTTL ...int) error { + ttl := ManagerSessionTTL + if len(withTTL) == 1 { + ttl = withTTL[0] + } logPrefix := fmt.Sprintf("[%s] %s", m.prompt, m.key) logutil.BgLogger().Info("start campaign owner", zap.String("ownerInfo", logPrefix)) - session, err := util2.NewSession(m.ctx, logPrefix, m.etcdCli, util2.NewSessionDefaultRetryCnt, ManagerSessionTTL) + session, err := util2.NewSession(m.ctx, logPrefix, m.etcdCli, util2.NewSessionDefaultRetryCnt, ttl) if err != nil { return errors.Trace(err) } diff --git a/owner/mock.go b/owner/mock.go index f33f2f37584ee..ead7e4a5de55e 100644 --- a/owner/mock.go +++ b/owner/mock.go @@ -131,7 +131,7 @@ func sleepContext(ctx context.Context, delay time.Duration) { } // CampaignOwner implements Manager.CampaignOwner interface. -func (m *mockManager) CampaignOwner() error { +func (m *mockManager) CampaignOwner(_ ...int) error { m.wg.Add(1) go func() { logutil.BgLogger().Debug("owner manager campaign owner", zap.String("category", "ddl"),