22 Raft 3 Catch-up Follower

Catching-up Followers

A server in cluster goes down, miss a lot of AppendEntry, rejoin cluster, leader sends another AppendEntry, cannot just append, need to make sure append in order - correctness

How to make sure?

1. Leader sends

  1. Entry to add new log
  2. prevLogIndex, index of previous log entry
  3. prevLogTerm, term of previous log entry

2. Server rejects to append if

  • don't agree on prevLogIndex or prevLogTerm

3. If leader got rejected

  • decrease prevLogIndex by 1 send again
  • until follower accept

This mechanism works because of Log Matching Property

  1. If two entries in different logs have the same index and term, then they store the same command.
  2. If two entries in different logs have the same index and term, then the logs are identical in all preceding entries.

Example

  1. rejected AppendEntries
    Pasted image 20251026013714.png

  2. Leader -1 to prevLogIndex, follower still reject
    Pasted image 20251026013816.png

  3. Leader -1 again, now follower accept
    Pasted image 20251026013935.png

  4. follower applies the AppendEntries
    Pasted image 20251026014010.png