In Raft when does a follower know an entry became committed? Can an out-of-date node can win a election?

1.7k Views Asked by At

In raft if a log replicated to majority, it is considered as committed in leader. Then leader send msg to follower to tell follower an entry become commit.If not, how and when follower know an entry become committed???

Another question,if an out of date can win an election in the following case? 5 nodes cluster, node A is the current leader.

A: 0 1 2 3 4

B: 0 1 2 3 4

C: 0 1 2 3 4

D: 0 1 2 3

E: 0 1

When node A (current leader) receive a request (entry 4), log it and replicated it to node B and node C. Then node A apply entry 4 in state machine and reply to client (In this point entry is considered committed by node B and node C or not ?). Then node A and node B crash, node D start new election vote itself and get vote by node E, then win the election. Will this case happen?

2

There are 2 best solutions below

0
On

How and when does a follower know an entry became committed???

  • He either received a heartbeat message from the current leader with the latest committed index.
  • Or, in case the leader failed before he could inform others about the new index, a new leader will be elected that eventually will commit new entries from the current term and thus implicitly declare that previous index (from the previous term) as committed.

Note: a leader may only commit an index from his own term (see §5.4.2 Committing entries from previous terms in (1)). If a new elected leader wants to know what is the latest committed index, he needs to commit a no-op(eration) entry right after his election.

An out-of-date node can win an election?

No. To receive a vote from another peer a node needs to have a log that is at-least-up-to-date1 as the log of the node he is trying to receive a vote from. (also the other node should not already grant a vote to somebody else in that given term)

1 Contains an entry from a later term. Or if the latest entries have the same term number it contains more entries.

0
On

The AppendEntries RPC that the leader sends to followers includes the commit index, the followers can apply those log entries to their state machines when they receive this from the leader. The followers only ever gets a commit index from the leader, it never calculates it itself. If the leader fails, the new leader will calculate the relevant commit index and send it with its AppendEntries RPC calls.

For the election question, D can't win the election, it needs 3 votes to win, and it'll not get a vote from C. Eventually C will start an election and win it and continue as leader.