From af62363acd398759bd367885700c91b9a51f3c8b Mon Sep 17 00:00:00 2001 From: Pavel Kalinnikov Date: Mon, 13 Mar 2023 19:41:32 +0000 Subject: [PATCH] raft: unindent maybeAppend Signed-off-by: Pavel Kalinnikov --- log.go | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/log.go b/log.go index 7b9888b1..5e7cefc3 100644 --- a/log.go +++ b/log.go @@ -107,24 +107,25 @@ func (l *raftLog) String() string { // maybeAppend returns (0, false) if the entries cannot be appended. Otherwise, // it returns (last index of new entries, true). func (l *raftLog) maybeAppend(index, logTerm, committed uint64, ents ...pb.Entry) (lastnewi uint64, ok bool) { - if l.matchTerm(index, logTerm) { - lastnewi = index + uint64(len(ents)) - ci := l.findConflict(ents) - switch { - case ci == 0: - case ci <= l.committed: - l.logger.Panicf("entry %d conflict with committed entry [committed(%d)]", ci, l.committed) - default: - offset := index + 1 - if ci-offset > uint64(len(ents)) { - l.logger.Panicf("index, %d, is out of range [%d]", ci-offset, len(ents)) - } - l.append(ents[ci-offset:]...) + if !l.matchTerm(index, logTerm) { + return 0, false + } + + lastnewi = index + uint64(len(ents)) + ci := l.findConflict(ents) + switch { + case ci == 0: + case ci <= l.committed: + l.logger.Panicf("entry %d conflict with committed entry [committed(%d)]", ci, l.committed) + default: + offset := index + 1 + if ci-offset > uint64(len(ents)) { + l.logger.Panicf("index, %d, is out of range [%d]", ci-offset, len(ents)) } - l.commitTo(min(committed, lastnewi)) - return lastnewi, true + l.append(ents[ci-offset:]...) } - return 0, false + l.commitTo(min(committed, lastnewi)) + return lastnewi, true } func (l *raftLog) append(ents ...pb.Entry) uint64 {