From 4b43824be941e08517fe1b64a895dad0a553e5d3 Mon Sep 17 00:00:00 2001 From: Yicheng Qin Date: Tue, 25 Nov 2014 11:28:25 -0800 Subject: [PATCH] raft: not compact log if the compact index < first index of the log It should ignore the compact operation instead of panic because the case that the log is restored from snapshot before executing compact is reasonable. --- raft/raft.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/raft/raft.go b/raft/raft.go index 1d9b28ac5..6d82fc7fe 100644 --- a/raft/raft.go +++ b/raft/raft.go @@ -534,6 +534,10 @@ func (r *raft) compact(index uint64, nodes []uint64, d []byte) { if index > r.raftLog.applied { panic(fmt.Sprintf("raft: compact index (%d) exceeds applied index (%d)", index, r.raftLog.applied)) } + if index < r.raftLog.offset { + //TODO: return an error? + return + } r.raftLog.snap(d, index, r.raftLog.term(index), nodes) r.raftLog.compact(index) }