I've spent a lot of time figuring out why it would be incorrect for `lastApplied` and `commitIndex` to not be kept as a single field.
Call this field `safeIndex`.
I thought of an edge case but even that self-corrects (at least from what I understand).
Say for example we had three nodes A, B, C. Each of them have logs with event IDs {1, 2, 3}. A is the leader and it just got to know that all entries are replicated to a majority and thus by the rules of commitment, it is committed. But before it can share safeIndex in the AppendEntries request to the followers, the node crashes.
Now C wins the election (by log completeness both B & C are eligible). It locally knows that safeIndex is 0. So in heartbeats it sends out the stale safeIndex. In my case, I made the followers have a branch in the apply(..) method so that the apply succeeds if localSafeIndex >= leaderSafeIndex. This means that logs don't suddenly rollback or auto apply.
Now C commits a no-op and sends {4} (by the rules of nextIndex initialization). When this succeeds the leader updates nextIndex and on response by a majority updates safeIndex to 4.
Other than some performance optimizations with fine-grained locking (or other synchronization techniques) there seems to be no advantage.
Since this has been raised a few times before, I'm likely understanding something wrong? Figure 2 is the only place that speaks of `lastApplied`
--
You received this message because you are subscribed to the Google Groups "raft-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to raft-dev+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/raft-dev/e956ae5b-8227-447f-abc4-c6746cb1160en%40googlegroups.com.