Im trying to learn Raft, but some edge cases are driving me crazy, and even with AI explanations, it’s hard to understand.
Here’s an example scenario:
- The leader has the following log:
1: A, 2: B, 3: C
- A new entry arrives:
4: D. The leader will append it to its log and replicate it to the followers.
One question I have is: is it possible for a follower to have a conflicting log like this?
1: A, 2: X, 3: C
Could this desync happen due to a leader crash or other failures?
Assuming this is possible, how should the follower reconcile its log with the leader’s?
From what I’ve read, the leader includes prevLogIndex and prevTerm in its append entries messages. This allows the follower to check the previous log entry, e.g., if the second-to-last log entry is 3: C and the follower also has 3: C, it considers the log consistent. But what happens to the conflicting 2: X entry?
If a follower wanted to commit its entries in this scenario, would it need to compare every log entry one by one with the leader’s log? That seems very expensive and inefficient. How does Raft efficiently handle this kind of inconsistency without checking each entry individually every time?