raft
raft copied to clipboard
Is `intMin(args.LeaderCommit, len(cm.log)-1)` needed?
In part 2, AppendEntries method, this if block
if args.LeaderCommit > cm.commitIndex {
cm.commitIndex = intMin(args.LeaderCommit, len(cm.log)-1)
cm.dlog("... setting commitIndex=%d", cm.commitIndex)
cm.newCommitReadyChan <- struct{}{}
}
I can't think of a scenario where commitIndex will be set to len(cm.log)-1), since the AE call from leader will always set the args.Entries from nextIndex[peerId] to the end of leader's log entries := cm.log[ni:], doesn't this ensure follower's log always be as complete as leader's?
so we can always set follower's commitIndex to args.LeaderCommit?
Am I crazy here?
This directly follows the algorithm outlined in the Raft paper for AppendEntries