-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Skip leadership check if the etcd instance is active processing heartbeats #18428
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -904,10 +904,26 @@ func (s *EtcdServer) revokeExpiredLeases(leases []*lease.Lease) { | |
| }) | ||
| } | ||
|
|
||
| // isActive checks if the etcd instance is still actively processing the | ||
| // heartbeat message (ticks). It returns false if no heartbeat has been | ||
| // received within 3 * tickMs. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why 3 election ticks? I think the correct value is somewhere between
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Read #18428 (comment).
I am not worry about this.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Then let's codify that is is inappropriate. Either working or failing validation. |
||
| func (s *EtcdServer) isActive() bool { | ||
| latestTickTs := s.r.getLatestTickTs() | ||
| threshold := 3 * time.Duration(s.Cfg.TickMs) * time.Millisecond | ||
| return latestTickTs.Add(threshold).After(time.Now()) | ||
| } | ||
|
|
||
| // ensureLeadership checks whether current member is still the leader. | ||
| func (s *EtcdServer) ensureLeadership() bool { | ||
| lg := s.Logger() | ||
|
|
||
| if s.isActive() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is incorrect assumption for 5 node clusters, getting a tick from 1 member is not effective way to confirm no other leader was elected. Imagine 3/2 network split with leader on side of 2. With your change the leader can continue think it's active by receiving ticks from 1 member, where on the other side of network 3 members have already elected new leader.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It has nothing to do with how many nodes the cluster has. The intention is to guard the case the node being stuck by itself, e.g stall write.
It's active, but it won't be a leader any more. It will step down automatically in such case due to losing quorum.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that the raft protocol handle the network partition case perfectly.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We are talking about 1 second before network partition, until heath probes fail for ElectionMs, the old leader will still think it's a leader before they resign. |
||
| lg.Debug("The member is active, skip checking leadership", | ||
| zap.Time("latestTickTs", s.r.getLatestTickTs()), | ||
| zap.Time("now", time.Now())) | ||
| return true | ||
| } | ||
|
|
||
| ctx, cancel := context.WithTimeout(s.ctx, s.Cfg.ReqTimeout()) | ||
| defer cancel() | ||
| if err := s.linearizableReadNotify(ctx); err != nil { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.