Nominate
NOMINATE - wait for nomination deadline to expire. If expiry is reached, this member becomes a candidate - it calculates the candidateTermId, clears voting records and moves to CANDIDATE_BALLOT. If another candidate gets there first, this member moves to FOLLOWER_BALLOT
On Entry¶
Enters from CANVASS, where it considered itself a candidate to become leader. It set a random nomination deadline, then moved to NOMINATE.
Description¶
The NOMINATE state is about waiting for the nomination deadline to expire before proceeding. There can be more than one member in this state, so the random deadline reduces the chance of them all proceeding at the same time and clashing. This is part of the Raft protocol. While waiting for the deadline, the member continues to publish CanvassPosition messages every 100 ms, as other members may still be starting up.
If it reaches the nomination deadline expiry time, it:
- calculates the candidateTermId, which is the proposed id of the next leadership term. It will be set to the highest candidateTermId the member has seen, plus one
- stores the candidateTermId in its node-state.dat file, along with the current logPosition (the position where the next term will start), and the current time as a timestamp
- clears the voting records it holds for the other members, then records a vote for itself, for the candidateTermId (each vote is for a specific leadership term and a member only votes once in each)
- moves to the CANDIDATE role
- moves to CANDIDATE_BALLOT, where it will send a RequestVote message to the other members
However, if the member receives a RequestVote from another member before its nomination deadline expires (see onRequestVote), it:
- stops waiting for its nomination deadline
- move to FOLLOWER_BALLOT, rather than CANDIDATE_BALLOT
candidateTermId¶
Each cluster member keeps track of the candidateTermId in their node-state.dat file. It is incremented in the NOMINATE state, just before moving to the next state, CANDIDATE_BALLOT, where it will be sent out in a RequestVote message.
Whenever a cluster member receives a RequestVote message, it also updates the value in its node-state.dat file. Each member is essentially trying to track the highest value seen across all cluster members, so next time it wants to propose a new one, it can propose the next highest number.
On Exit¶
Either it is ready to request votes from the other members and moves to CANDIDATE_BALLOT, or another member got there first, so this member votes for it and moves to FOLLOWER_BALLOT.