Skip to content

Commit

Permalink
ahead resign
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <jinhao.hu@pingcap.com>
  • Loading branch information
HuSharp committed Jan 5, 2024
1 parent 34cb477 commit ceb0c7c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/member/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ func (m *EmbeddedEtcdMember) CampaignLeader(ctx context.Context, leaseTimeout in
})

if m.leadership.GetCampaignTimesNum() >= campaignLeaderFrequencyTimes {
m.leadership.ResetCampaignTimes()
if err := m.ResignEtcdLeader(ctx, m.Name(), ""); err != nil {
return err
}
m.leadership.ResetCampaignTimes()
return errs.ErrLeaderFrequentlyChange.FastGenByArgs(m.Name(), m.GetLeaderPath())
}

Expand Down
5 changes: 3 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1784,11 +1784,12 @@ func (s *Server) campaignLeader() {
return
}
// check healthy status of etcd leader.
if s.member.GetLeadership().GetUnHealthyTimesNum() > unhealthyLeaderLeaseTimes {
s.member.GetLeadership().ResetUnHealthyTimesNum(ctx)
if s.member.GetLeadership().GetUnHealthyTimesNum() >= unhealthyLeaderLeaseTimes {
if err := s.member.ResignEtcdLeader(ctx, s.member.Name(), ""); err != nil {
return

Check warning on line 1789 in server/server.go

View check run for this annotation

Codecov / codecov/patch

server/server.go#L1789

Added line #L1789 was not covered by tests
}
s.member.GetLeadership().ResetUnHealthyTimesNum(ctx)
return
}
case <-ctx.Done():
// Server is closed and it should return nil.
Expand Down

0 comments on commit ceb0c7c

Please sign in to comment.