raft icon indicating copy to clipboard operation
raft copied to clipboard

Is `intMin(args.LeaderCommit, len(cm.log)-1)` needed?

Open aiqingyuyan opened this issue 2 years ago • 1 comments

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?

aiqingyuyan avatar Nov 24 '23 22:11 aiqingyuyan

This directly follows the algorithm outlined in the Raft paper for AppendEntries

eliben avatar Nov 25 '23 23:11 eliben