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]>
Signed-off-by: chenyangyang.cy <[email protected]>
  • Loading branch information
chenyang8094 committed Aug 18, 2023
1 parent c1b9647 commit 68db708
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 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 68db708

Please sign in to comment.