I was reading Kuujo's answer to one of the questions on leader election here: RAFT election restrictions
That's right. That the leader has all prior committed entries is a property of the election algorithm, but the actual commitIndex is in no way involved in the election algorithm. In fact, it is entirely possible for a leader to get elected without some entries that have been stored on a majority of servers. This is why commitment is not always determined by counting replicas and it's why leaders must commit an entry from their current term to call entries from past terms committed. See figure 8 in the Raft paper for an explanation of this. – kuujo May 17, 2016 at 21:35
Question: How can a leader get elected, if it doesnt have entries that have been stored on a majority of servers? Doesnt it mean that this candidate is not up-to-date, so shouldnt win an election?
A log on a node contains committed and not committed entries. Non committed entries may be on a majority on nodes - but that does not makes them committed.
A candidate asks for votes, followers decided if the log is in a good state be using this rule (from the raft paper):
In addition to:
And:
This situation happens when a leader sends messages to a majority of nodes and fails before collecting confirmations.
Edit: forgot to mention, here is how a leader decides on commit index
Key item here is the check if the term is the currentTerm, which is owned by this leader. So if the leader crashes, a new one won't be able to declare an entry committed till that new leader appends an entry for its new term.
Edit: from two comments
a) Stored is not committed. A committed entry is the one, which a node may apply to its state machine. This may happen only when a leader gets a record sent to majority for a term owned by that leader. When this happens, all other stored-but-not-committed entries are considered committed as well and those are applied to state machines as well. You touched the importance of stored vs committed in the other question about Figure 8 from Raft paper: a record may be stored on majority of nodes due to a combination of re-elections, and that record is not considered committed and may be overridden.
b) Commenting inline: