Does Raft send AppendEntries with logs right after election?

Viewed 119

I have a question about a detailed behavior of log replication in Raft.

Figure. 2 of extended Raft paper said:

  • nextIndex is initialized to leader last log + 1 after election
  • If last log index >= nextIndex for a follower: send AppendEntries RPC with log entries starting at nextIndex.

So, in my understanding, the following situation can happens.

  • S1 (Leader, Term:10) received command X from client.
  • S2 (Follower, Term:10) starts to election and becomes Leader
  • ...
  • S1 (Leader, Term:13) elected as Leader (reinitialized nextIndex to leader last log + 1)
  • Then, S1 does not send Append Entries RPC with logs including command X to followers until received next command from client.

But, (d) of Fig.8 looks sending Append Entries RPC with "3" right after S5 was elected. Fig.8

Could anyone tell me why this happens? Or am I mistaken?

1 Answers

Directly after an election the Leader sends heartbeats to the followers to establish itself as the new Leader. If there are no client requests the Leader sends no entries but it still sends its prevLogIndex and its prevLogTerm with the heartbeat. If there is a mismatch with a follower the nextIndex of the follower is decremented. I think the next Heartbeat then includes the missing entry and when there is finally a match of prevLogIndex and prevLogTerm with the follower, the missing entries can be applied to the Follower. Some things are also implementation dependent.

Related