Why does a Raft leader only count replicas to commit entries from its own term, even if an entry from an earlier term is on a majority?
Sketch your own answer first, then compare it with the one below.
A strong answer
Because an entry from an earlier term can be on a majority and still be overwritten. A later leader with a higher-term entry at the same index can win an election without it, because the election restriction compares terms first. Counting replicas of the old entry and committing it would then lose a committed entry when that leader overwrites it.
Raft's rule is that a leader commits an entry from a previous term only indirectly, by committing an entry from its own term after it. Log matching then guarantees everything before that entry on the same nodes, including the old one. The paper's figure of the scenario is the standard thing to sketch here.
In practice a new leader appends a no-op entry in its own term as soon as it is elected. That commits the earlier entries at once instead of waiting for the next client write.
Sources
- Diego Ongaro, John Ousterhout (2014). In Search of an Understandable Consensus Algorithm.