From 9b04e4df459358cb82a83cabbb993b851a299c36 Mon Sep 17 00:00:00 2001 From: Clement Date: Tue, 24 Sep 2024 18:23:20 +0800 Subject: [PATCH] separate maybeCompactRaftLog function to compact raft log independently from snapshots Signed-off-by: Clement --- server/etcdserver/server.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/etcdserver/server.go b/server/etcdserver/server.go index 2540cc5b295..378d4579672 100644 --- a/server/etcdserver/server.go +++ b/server/etcdserver/server.go @@ -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()