Skip to content

Commit 54925de

Browse files
committed
log: consolidate the commited entry rewrite check
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]>
1 parent 8425e2b commit 54925de

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

log.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ func (l *raftLog) maybeAppend(a logSlice, committed uint64) (lastnewi uint64, ok
109109
if !ok {
110110
return 0, false
111111
}
112-
if match.index < a.lastIndex() && match.index < l.committed {
113-
l.logger.Panicf("entry %d is already committed [committed(%d)]", match.index+1, l.committed)
114-
}
115112

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

0 commit comments

Comments
 (0)