Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoid_service,owner: change autoid service's etcd lease to 10s (#46455) #46653

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion autoid_service/autoid.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ func New(selfAddr string, etcdAddr []string, store kv.Storage, tlsConfig *tls.Co

func newWithCli(selfAddr string, cli *clientv3.Client, store kv.Storage) *Service {
l := owner.NewOwnerManager(context.Background(), cli, "autoid", selfAddr, autoIDLeaderPath)
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 @@ -87,7 +87,7 @@ func (*mockManager) SetOwnerOpValue(_ context.Context, op OpType) error {
}

// CampaignOwner implements Manager.CampaignOwner interface.
func (m *mockManager) CampaignOwner() error {
func (m *mockManager) CampaignOwner(_ ...int) error {
m.toBeOwner()
return nil
}
Expand Down