Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions d-engine-core/src/config/raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,9 +619,9 @@ fn default_max_log_entries_before_snapshot() -> u64 {
/// Default cooldown duration between snapshot checks.
///
/// Prevents constant evaluation of snapshot conditions in tight loops.
/// Currently set to 1 hour (3600 seconds).
/// Reduced from 3600s to 60s to allow timely log compaction under typical workloads.
fn default_snapshot_cool_down_since_last_check() -> Duration {
Duration::from_secs(3600)
Duration::from_secs(60)
}

/// Default number of historical snapshots to retain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::sync::atomic::Ordering;
use std::time::Duration;

use tracing::trace;
use tracing::warn;

use super::SnapshotContext;
use super::SnapshotPolicy;
Expand All @@ -30,11 +31,12 @@ impl SnapshotPolicy for LogSizePolicy {
return false;
}

// Cooldown check using atomic operations
// Cooldown check — Relaxed is sufficient since the CAS on
// is_checking provides actual mutual exclusion.
let now = timestamp_millis();
let last = self.last_checked.load(Ordering::Acquire);
let last = self.last_checked.load(Ordering::Relaxed);

if now - last < self.cooldown_ms {
if now.saturating_sub(last) < self.cooldown_ms {
return false;
}

Expand All @@ -47,9 +49,20 @@ impl SnapshotPolicy for LogSizePolicy {
return false;
}

let should_trigger = self.calculate_lag(ctx) >= self.threshold.load(Ordering::Relaxed);
let lag = self.calculate_lag(ctx);
let threshold = self.threshold.load(Ordering::Relaxed);

if threshold > 0 && lag >= threshold.saturating_mul(10) {
warn!(
lag,
threshold,
"Log lag exceeds 10x snapshot threshold — snapshots may not be keeping up"
);
}

let should_trigger = lag >= threshold;
if should_trigger {
self.last_checked.store(now, Ordering::Release);
self.last_checked.store(now, Ordering::Relaxed);
}
Comment thread
JoshuaChi marked this conversation as resolved.

self.is_checking.store(false, Ordering::Release);
Expand Down
Loading