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

Merged
merged 3 commits into from
Sep 4, 2023
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 @@ -306,7 +306,8 @@
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)

Check warning on line 310 in autoid_service/autoid.go

View check run for this annotation

Codecov / codecov/patch

autoid_service/autoid.go#L310

Added line #L310 was not covered by tests
tiancaiamao marked this conversation as resolved.
Show resolved Hide resolved
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 @@
// 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 @@
}

// 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]
}

Check warning on line 180 in owner/manager.go

View check run for this annotation

Codecov / codecov/patch

owner/manager.go#L176-L180

Added lines #L176 - L180 were not covered by tests
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)

Check warning on line 183 in owner/manager.go

View check run for this annotation

Codecov / codecov/patch

owner/manager.go#L183

Added line #L183 was not covered by tests
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 @@ -124,7 +124,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.wg.Add(1)
go func() {
logutil.BgLogger().Debug("owner manager campaign owner", zap.String("category", "ddl"),
Expand Down