#635·raft

The parameter Should be C_old configuration in runFollower()?

Author: zivfutureCreated Feb 20, 2025Updated May 29, 2026

code here: https://github.com/hashicorp/raft/blob/8f99c150c37d3f7ded1c13f1f5f52b60374632b6/raft.go#L242

see the comment please.

go
// 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
	}
}