Skip to content

Commit

Permalink
do not force compact unreplicated entries (#12181)
Browse files Browse the repository at this point in the history
close #12161

Signed-off-by: tabokie <xy.tao@outlook.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
  • Loading branch information
tabokie and ti-chi-bot committed Mar 21, 2022
1 parent 75526df commit ac32d5c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions components/raftstore/src/store/fsm/peer.rs
Expand Up @@ -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:
Expand Down

0 comments on commit ac32d5c

Please sign in to comment.