Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aiqingyuyan opened this issue Nov 24, 2023 · 1 comment
Open

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

aiqingyuyan opened this issue Nov 24, 2023 · 1 comment

Comments

@aiqingyuyan
Copy link

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?

@eliben
Copy link
Owner

eliben commented Nov 25, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants