-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Description
code here:
Line 242 in 8f99c15
| if hasVote(r.configurations.latest, r.localID) { |
see the comment please.
// it is makesense here
if r.configurations.latestIndex == 0 {
if !didWarn {
r.logger.Warn("no known peers, aborting election")
didWarn = true
}
}
// The code is: WHEN the configuration is committed AND current node is not a voter THEN abort election
// Why handle this situation separately?
// Why not merge this into the 'else' below?
else if r.configurations.latestIndex == r.configurations.committedIndex &&
!hasVote(r.configurations.latest, r.localID) {
if !didWarn {
r.logger.Warn("not part of stable configuration, aborting election")
didWarn = true
}
} else {
metrics.IncrCounter([]string{"raft", "transition", "heartbeat_timeout"}, 1)
// The code is:
// WHEN (configuration is uncommitted) AND current node is a voter THEN into candidate
// WHEN (configuration is committed OR configuration is uncommitted) AND current node is not a voter THEN abort election.
//
// Why not implement this logic in this way and delete the "else if" block:
// WHEN (configuration is committed OR configuration is uncommitted) AND current node is a voter THEN into candidate
// WHEN (configuration is committed OR configuration is uncommitted) AND current node is not a voter THEN abort election.
if hasVote(r.configurations.latest, r.localID) {
r.logger.Warn("heartbeat timeout reached, starting election", "last-leader-addr", lastLeaderAddr, "last-leader-id", lastLeaderID)
r.setState(Candidate)
return
} else if !didWarn {
r.logger.Warn("heartbeat timeout reached, not part of a stable configuration or a non-voter, not triggering a leader election")
didWarn = true
}
}Metadata
Metadata
Assignees
Labels
No labels