Skip to content

Commit

Permalink
autoid_service,owner: change autoid service's etcd lease to 10s (#46455)
Browse files Browse the repository at this point in the history
close #46454
  • Loading branch information
tiancaiamao authored Sep 4, 2023
1 parent 8b9a90d commit 18ecfba
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion autoid_service/autoid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
10 changes: 7 additions & 3 deletions owner/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion owner/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit 18ecfba

Please sign in to comment.