Candidate Ballot
CANDIDATE_BALLOT - candidate requests votes and waits for them, moves to LEADER_LOG_REPLICATION if won the election, otherwise moves back to CANVASS
On Entry¶
Enters from NOMINATE, where the member reached the end of its random nomination deadline, then moved to this state to request votes.
Description¶
It sends a RequestVote message to the other members, which contains:
- logLeadershipTermId - highest leadership term in its Log Recording (-1 if empty)
- logPosition - highest position in its Log Recording (Archive appendPosition, 0 if empty)
- candidateTermId - proposed next leadership term
See onRequestVote for details of how members handle the message, but essentially, each member responds with a Vote message, and vote only once in each leadership term (candidateTermId). The Vote can be for or against (veto) the member.
When a Vote is received (onVote), it is recorded in the ClusterMember object for the sender.
Each time round its duty cycle, the member checks all the ClusterMember objects to see if it isUnanimousLeader, which means all the members have voted for it (this includes its own vote for itself).
If it is not the unanimous leader and it reaches the election timeout (1 second), it checks to see if it isQuorumLeader. Waiting gives other members a chance to veto the candidate if they need to. Quorum leader means it has a majority of the votes, with no votes against it. This can happen if a minority of the cluster members are not running
If it has become the leader, it sets its leadershipTermId to the candidateTermId, then moves to LEADER_LOG_REPLICATION.
If it has not become the leader by the election timeout, it moves back to CANVASS.
On Exit¶
One of the following occurs:
- if it has been voted leader, it moves to LEADER_LOG_REPLICATION
- if it receives a NewLeadershipTerm message from another member that became the leader, it becomes a follower and moves to one of FOLLOWER_LOG_REPLICATION or FOLLOWER_REPLAY
- if neither of the above happen and the election times out, it moves back to CANVASS