Skip to content

Commit

Permalink
server: fix resign owner API (#720)
Browse files Browse the repository at this point in the history
Signed-off-by: dongmen <[email protected]>
  • Loading branch information
asddongmen authored Dec 24, 2024
1 parent f19035c commit e81bc1a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions server/module_election.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ func (e *elector) campaignCoordinator(ctx context.Context) error {
coordinatorVersion, 10000, time.Minute)
e.svr.setCoordinator(co)
err = co.Run(ctx)

// When coordinator exits, we need to stop it.
e.svr.coordinator.AsyncStop()
e.svr.setCoordinator(nil)

Expand All @@ -154,18 +156,26 @@ func (e *elector) campaignCoordinator(ctx context.Context) error {
log.Info("coordinator resigned successfully",
zap.String("captureID", string(e.svr.info.ID)),
zap.Int64("coordinatorVersion", coordinatorVersion))
if err != nil {

// 1. If the context is cancelled by the parent context, the loop should exit at the next campaign.
// 2. If the context is cancelled within the coordinator, it means the coordinator is exited by Resign API,
// we should keep the loop running to try to election coordinator again.
// So, regardless of the cause of the context.Canceled, we should not exit here.
// We should proceed to the next iteration of the loop, allowing subsequent logic to make the determination.
if err != nil && err != context.Canceled {
log.Warn("run coordinator exited with error",
zap.String("captureID", string(e.svr.info.ID)),
zap.Int64("coordinatorVersion", coordinatorVersion),
zap.Error(err))
// for errors, return error and let server exits or restart
return errors.Trace(err)
}
// if coordinator exits normally, continue the campaign loop and try to election coordinator again

// If coordinator exits normally, continue the campaign loop and try to election coordinator again
log.Info("run coordinator exited normally",
zap.String("captureID", string(e.svr.info.ID)),
zap.Int64("coordinatorVersion", coordinatorVersion))
zap.Int64("coordinatorVersion", coordinatorVersion),
zap.String("error", err.Error()))
}
}

Expand Down Expand Up @@ -222,7 +232,6 @@ func (e *elector) campaignLogCoordinator(ctx context.Context) error {
}

// FIXME: get log coordinator version from etcd and add it to log

log.Info("campaign log coordinator successfully",
zap.String("captureID", string(e.svr.info.ID)))

Expand Down

0 comments on commit e81bc1a

Please sign in to comment.