Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp committed Nov 14, 2023
1 parent 0b032cc commit bacc30a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions pkg/member/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const (
moveLeaderTimeout = 5 * time.Second
dcLocationConfigEtcdPrefix = "dc-location"
// If the campaign times is more than this value in `campaignTimesRecordTimeout`, the PD will resign and campaign again.
campaignLeaderFrequencyTimes = 5
campaignLeaderFrequencyTimes = 3
)

// EmbeddedEtcdMember is used for the election related logic. It implements Member interface.
Expand Down Expand Up @@ -181,9 +181,9 @@ func (m *EmbeddedEtcdMember) GetLastLeaderUpdatedTime() time.Time {
// and make it become a PD leader.
// leader should be changed when campaign leader frequently.
func (m *EmbeddedEtcdMember) CampaignLeader(ctx context.Context, leaseTimeout int64) error {
if len(m.leadership.CampaignTimes) > campaignLeaderFrequencyTimes {
log.Warn("campaign times is too frequent, resign and campaign again", zap.String("leader-name", m.Name()),
zap.Int("campaign-times", len(m.leadership.CampaignTimes)), zap.String("leader-key", m.GetLeaderPath()))
if len(m.leadership.CampaignTimes) >= campaignLeaderFrequencyTimes {
log.Warn("campaign times is too frequent, resign and campaign again",
zap.String("leader-name", m.Name()), zap.String("leader-key", m.GetLeaderPath()))
// remove all campaign times
m.leadership.CampaignTimes = nil
return m.ResignEtcdLeader(ctx, m.Name(), "")
Expand Down
2 changes: 1 addition & 1 deletion tests/server/member/member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func TestCampaignLeaderFrequently(t *testing.T) {
leader := cluster.GetLeader()
re.NotEmpty(cluster.GetLeader())

for i := 0; i < 6; i++ {
for i := 0; i < 3; i++ {
cluster.GetServers()[cluster.GetLeader()].ResetPDLeader()
cluster.WaitLeader()
}
Expand Down

0 comments on commit bacc30a

Please sign in to comment.