-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
raft: don't apply entries when applying snapshot #14721
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,9 +181,13 @@ func (l *raftLog) unstableEntries() []pb.Entry { | |
// If applied is smaller than the index of snapshot, it returns all committed | ||
// entries after the index of snapshot. | ||
func (l *raftLog) nextCommittedEnts() (ents []pb.Entry) { | ||
off := max(l.applied+1, l.firstIndex()) | ||
if l.committed+1 > off { | ||
ents, err := l.slice(off, l.committed+1, l.maxNextCommittedEntsSize) | ||
if l.hasPendingSnapshot() { | ||
// See comment in hasNextCommittedEnts. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could even structure this method as
That way there's no duplication in logic between the two and one need not worry about them diverging via a future change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
return nil | ||
} | ||
if l.committed > l.applied { | ||
lo, hi := l.applied+1, l.committed+1 // [lo, hi) | ||
ents, err := l.slice(lo, hi, l.maxNextCommittedEntsSize) | ||
if err != nil { | ||
l.logger.Panicf("unexpected error when getting unapplied entries (%v)", err) | ||
} | ||
|
@@ -195,8 +199,13 @@ func (l *raftLog) nextCommittedEnts() (ents []pb.Entry) { | |
// hasNextCommittedEnts returns if there is any available entries for execution. | ||
// This is a fast check without heavy raftLog.slice() in nextCommittedEnts(). | ||
func (l *raftLog) hasNextCommittedEnts() bool { | ||
off := max(l.applied+1, l.firstIndex()) | ||
return l.committed+1 > off | ||
if l.hasPendingSnapshot() { | ||
// If we have a snapshot to apply, don't also return any committed | ||
// entries. Doing so raises questions about what should be applied | ||
// first. | ||
return false | ||
} | ||
return l.committed > l.applied | ||
tbg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// hasPendingSnapshot returns if there is pending snapshot waiting for applying. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stale comment.