Skip to content

Commit

Permalink
log: consolidate the commited entry rewrite check
Browse files Browse the repository at this point in the history
The append function call right after this does the same check, we don't
need to do this in two places. TestLogMaybeAppend exercises these
panics, and confirms the behaviour is the same after the first panic is
removed.

Signed-off-by: Pavel Kalinnikov <[email protected]>
  • Loading branch information
pav-kv committed Feb 7, 2024
1 parent 17f5596 commit b636292
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ func (l *raftLog) maybeAppend(a logSlice, committed uint64) (lastnewi uint64, ok
if !ok {
return 0, false
}
if match.index < a.lastIndex() && match.index < l.committed {
l.logger.Panicf("entry %d is already committed [committed(%d)]", match.index+1, l.committed)
}

// Fast-forward to the first mismatching or missing entry.
// NB: prev.index <= match.index <= a.lastIndex(), so the sub-slicing is safe.
Expand All @@ -129,8 +126,8 @@ func (l *raftLog) append(ents ...pb.Entry) uint64 {
if len(ents) == 0 {
return l.lastIndex()
}
if after := ents[0].Index - 1; after < l.committed {
l.logger.Panicf("after(%d) is out of range [committed(%d)]", after, l.committed)
if mismatch := ents[0].Index; mismatch <= l.committed {
l.logger.Panicf("entry %d is already committed [committed(%d)]", mismatch, l.committed)
}
l.unstable.truncateAndAppend(ents)
return l.lastIndex()
Expand Down

0 comments on commit b636292

Please sign in to comment.