Skip leadership check if the etcd instance is active processing heartbeat
Signed-off-by: Benjamin Wang <benjamin.ahrtr@gmail.com>
This commit is contained in:
@ -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.
|
||||
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() {
|
||||
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 {
|
||||
|
Reference in New Issue
Block a user