21 Raft 2 Leader Re-Election
Leader Election
- Leader sends
AppendEntrieswhen client submit operation - Leader also sends
AppendEntriesas a heartbeat "I'm still alive" - If leader unresponsive, after Election Timeout, server start election
Election Timeout: Must be randomized such that, most of the time, exactly 1 server starts an election at a time,
Election Process
During election, server will
- become
CANDIDATE - increase term number
- solicit votes
- if get majority vote, become leader, otherwise, wait & repeat process later
We must guarantee
- At Most One leader for a term
- The elected leader must have All Committed log entries
Each voter guarantees
- Only vote once: use
votedForto track who it voted for incurrentTerm- So that no 2 leaders can both have the majority of vote
- Only vote candidate with all log it has (or more):
- ensure elected leaders have all log entries present on majority of servers, thus all newly elected leaders have all committed entries!
Server will vote the first time it sees aRequestVotemsg for a new term, if it comes from an up-to-date server.

Up-to-date Server
Server will cast vote based on requester's log length and last term
- When requester has bigger term
- When they have same term but requester has longer log length
It is impossible for a server without all committed logs to be elected because the majority must have had all committed entries, so they will only vote for a leader with all committed entries.