From 68db7087e1e4ff9ff3835e82836db81c1b0fc414 Mon Sep 17 00:00:00 2001 From: "chenyangyang.cy" Date: Wed, 16 Aug 2023 13:35:39 +0800 Subject: [PATCH] Handle ErrCompacted errors for Compact in raftexample Signed-off-by: Chen Yang <809476530@qq.com> Signed-off-by: chenyangyang.cy --- contrib/raftexample/raft.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/contrib/raftexample/raft.go b/contrib/raftexample/raft.go index 14f1aca8082..18b5354dd32 100644 --- a/contrib/raftexample/raft.go +++ b/contrib/raftexample/raft.go @@ -392,10 +392,13 @@ func (rc *raftNode) maybeTriggerSnapshot(applyDoneC <-chan struct{}) { compactIndex = rc.appliedIndex - snapshotCatchUpEntriesN } if err := rc.raftStorage.Compact(compactIndex); err != nil { - panic(err) + if err != raft.ErrCompacted { + panic(err) + } + } else { + log.Printf("compacted log at index %d", compactIndex) } - log.Printf("compacted log at index %d", compactIndex) rc.snapshotIndex = rc.appliedIndex }