Skip to content

Commit

Permalink
separate maybeCompactRaftLog function to compact raft log independent…
Browse files Browse the repository at this point in the history
…ly from snapshots

Signed-off-by: Clement <[email protected]>
  • Loading branch information
clement2026 committed Sep 24, 2024
1 parent dff5305 commit 9b04e4d
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions server/etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2177,12 +2177,11 @@ func (s *EtcdServer) maybeCompactRaftLog(ep *etcdProgress) {
// Retain all log entries up to the latest snapshot index to ensure any member can recover from that snapshot.
// Beyond the snapshot index, preserve the most recent s.Cfg.SnapshotCatchUpEntries entries in memory.
// This allows slow followers to catch up by synchronizing entries instead of requiring a full snapshot transfer.
// Only compact raft log once every N applies
if ep.snapi <= s.Cfg.SnapshotCatchUpEntries {
return
}

// make sure compacti >= 0, because s.r.raftStorage.Compact(compacti) always returns ErrCompacted if compacti <= 0
// make sure compacti > 0, because s.r.raftStorage.Compact(compacti) returns ErrCompacted if compacti = 0
compacti := ep.snapi - s.Cfg.SnapshotCatchUpEntries

lg := s.Logger()
Expand Down

0 comments on commit 9b04e4d

Please sign in to comment.