From a133debb52282f1a392dae9c6b83555b901f29ce 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 --- contrib/raftexample/raft.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/contrib/raftexample/raft.go b/contrib/raftexample/raft.go index 14f1aca80821..0373ea789544 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 }