Skip to content

Commit

Permalink
Handle ErrCompacted errors for Compact in raftexample
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Yang <[email protected]>
  • Loading branch information
chenyang8094 committed Aug 16, 2023
1 parent c1b9647 commit 8cf15c7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions contrib/raftexample/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 8cf15c7

Please sign in to comment.