0

In Search of an Understandable Consensus Algorithm (Extended Version):

Upon election: send initial empty AppendEntries RPCs (heartbeat) to each server; repeat during idle periods to prevent election timeouts

Why sends empty AppendEntries RPCs but not carry logs? When does leader sends AppendEntries RPCS with logs?

Gomo
  • 47
  • 6

1 Answers1

0

AppendEntries RPCs with no entries are known as heartbeats, which the leader sends periodically to the followers to tell them that he's alive. The followers each have a different timer that resets everytime the they receive an heartbeat. If this timer reaches zero, it means that the leader may have crashed and the follower whose timer reached zero switches to the Candidate state to try to be the new Leader.

The leader sends AppendEntries RPC's with logs when the leader receives any requests from the clients and stores them in its own log. It then sends the new entries to its followers using AppendEntries.

Here you can visualize raft in action, they all start in a follower state and since there is no leader to send heartbeats, one of them switches to candidate state and becomes the Leader.

There could be another dedicated RPC to be the heartbeat but Raft uses AppendEntries because it does the job. The heartbeat is also used to update tell the followers who the current leader is and which term they are on.

sfmelo
  • 21
  • 3
  • Thank you for your answer. I know why leader must sends heartbeats to follower, but what I really want to know is, why didn't leader take logs conveniently. I think leader does not know which logs the followers need initially, so it must send empty AppendEntries RPCs to match with followers. – Gomo Nov 11 '20 at 03:21