From ac32d5c8099a85994a9790ae1840755033dd0fac Mon Sep 17 00:00:00 2001 From: Xinye Tao Date: Mon, 21 Mar 2022 21:40:32 +0800 Subject: [PATCH] do not force compact unreplicated entries (#12181) close tikv/tikv#12161 Signed-off-by: tabokie Co-authored-by: Ti Chi Robot --- components/raftstore/src/store/fsm/peer.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/components/raftstore/src/store/fsm/peer.rs b/components/raftstore/src/store/fsm/peer.rs index 575e2332c7a..96f3d5728dd 100644 --- a/components/raftstore/src/store/fsm/peer.rs +++ b/components/raftstore/src/store/fsm/peer.rs @@ -4439,13 +4439,13 @@ where let first_idx = self.fsm.peer.get_store().first_index(); - let mut compact_idx = if force_compact - // Too many logs between applied index and first index. - || (applied_idx > first_idx && applied_idx - first_idx >= self.ctx.cfg.raft_log_gc_count_limit) - // Raft log size ecceeds the limit. + let mut compact_idx = if force_compact && replicated_idx > first_idx { + replicated_idx + } else if (applied_idx > first_idx + && applied_idx - first_idx >= self.ctx.cfg.raft_log_gc_count_limit) || (self.fsm.peer.raft_log_size_hint >= self.ctx.cfg.raft_log_gc_size_limit.0) { - std::cmp::max(first_idx + (last_idx - first_idx) / 4, replicated_idx) + std::cmp::max(first_idx + (last_idx - first_idx) / 2, replicated_idx) } else if replicated_idx < first_idx || last_idx - first_idx < 3 { // In the current implementation one compaction can't delete all stale Raft logs. // There will be at least 3 entries left after one compaction: