-
Notifications
You must be signed in to change notification settings - Fork 719
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
member: avoid frequent campaign times #7301
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
@@ -152,7 +152,7 @@ func (s *Server) primaryElectionLoop() { | |||
|
|||
func (s *Server) campaignLeader() { | |||
log.Info("start to campaign the primary/leader", zap.String("campaign-resource-manager-primary-name", s.participant.Name())) | |||
if err := s.participant.CampaignLeader(s.cfg.LeaderLease); err != nil { | |||
if err := s.participant.CampaignLeader(s.Context(), s.cfg.LeaderLease); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, pass context to make sure resign
can be used
05e25f3
to
eaecc64
Compare
eaecc64
to
a16c1c9
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #7301 +/- ##
==========================================
- Coverage 74.35% 74.31% -0.04%
==========================================
Files 451 451
Lines 48863 48877 +14
==========================================
- Hits 36330 36325 -5
- Misses 9324 9336 +12
- Partials 3209 3216 +7
Flags with carried forward coverage won't be shown. Click here to find out more. |
pkg/election/leadership.go
Outdated
@@ -105,7 +109,8 @@ func (ls *Leadership) GetLeaderKey() string { | |||
} | |||
|
|||
// Campaign is used to campaign the leader with given lease and returns a leadership | |||
func (ls *Leadership) Campaign(leaseTimeout int64, leaderData string, cmps ...clientv3.Cmp) error { | |||
func (ls *Leadership) Campaign(ctx context.Context, leaseTimeout int64, leaderData string, cmps ...clientv3.Cmp) error { | |||
ls.CampaignTimes = append(ls.CampaignTimes, *cache.NewStringTTL(ctx, 5*time.Second, 5*time.Minute)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is its length always increase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace to slice without ttl
pkg/election/leadership.go
Outdated
@@ -62,6 +63,9 @@ type Leadership struct { | |||
keepAliveCtx context.Context | |||
keepAliveCancelFunc context.CancelFunc | |||
keepAliveCancelFuncLock syncutil.Mutex | |||
// CampaignTimes is used to record the campaign times of the leader in 5min. | |||
// To avoid the leader campaign too frequently. | |||
CampaignTimes []cache.TTLString |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TTLString is container, no needs to use array.BTW, you can only use array not ttlcache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch. fixed
91d410c
to
99db858
Compare
99db858
to
7ccde6b
Compare
Signed-off-by: husharp <jinhao.hu@pingcap.com>
fcc8695
to
0b032cc
Compare
Being tested on tcms... please DO NOT merge in now :) |
/hold |
880d627
to
bacc30a
Compare
/unhold |
/merge |
@bufferflies: It seems you want to merge this PR, I will help you trigger all the tests: /run-all-tests You only need to trigger
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
This pull request has been accepted and is ready to merge. Commit hash: bacc30a
|
@HuSharp: Your PR was out of date, I have automatically updated it for you. If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
/cherry-pick release-7.5 |
In response to a cherrypick label: new pull request created to branch |
@ti-chi-bot: new pull request could not be created: failed to create pull request against tikv/pd#release-7.5 from head ti-chi-bot:cherry-pick-7301-to-release-7.5: status code 422 not one of [201], body: {"message":"Validation Failed","errors":[{"resource":"PullRequest","code":"custom","message":"A pull request already exists for ti-chi-bot:cherry-pick-7301-to-release-7.5."}],"documentation_url":"https://docs.github.com/rest/pulls/pulls#create-a-pull-request"} In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
close #7251, ref #7377 when pd leader frequently campaign leader, but etcd leader did not change. We need to prevent this pd leader campaign and resign to another member. Signed-off-by: husharp <jinhao.hu@pingcap.com> Co-authored-by: husharp <jinhao.hu@pingcap.com> Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
What problem does this PR solve?
Issue Number: Close #7251, ref #7377
What is changed and how does it work?
Check List
Tests
Release note