Repository navigation
fix #290: reduce snapshot cooldown and fix check throttling - #354
Conversation
- Reduce default cooldown from 3600s to 60s - Fix: use saturating_sub to handle clock jumps - Fix: use Relaxed ordering for last_checked (CAS lock already provides mutual exclusion) - Add: warning log when lag exceeds 10x snapshot threshold Implementation based on @fizikarubi's analysis in PR #338. The PR was delayed due to unrelated CI issues in the codebase (since resolved), but the technical approach was sound and is applied here. Co-authored-by: fizikarubi <fizikarubi@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughReduced the default snapshot cooldown from 3600s to 60s and tightened snapshot log-size policy: added a heavy-lag warning, switched atomic loads/stores to Relaxed ordering, used saturating subtraction for time, and refactored decision locals. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@d-engine-core/src/config/raft.rs`:
- Around line 622-623: The doc comment on LogSizePolicy incorrectly states that
the cooldown "shrinks automatically" as log lag approaches the snapshot
threshold; update the documentation for the LogSizePolicy struct/impl to reflect
the actual runtime behavior by either (A) removing or rephrasing the adaptive
language to state that the provided cooldown is a fixed/base value and that no
adaptive shrinking is performed, or (B) if adaptive cooldown is intended,
implement the adaptive logic in the LogSizePolicy methods (e.g., where cooldown
is computed) so the cooldown value is reduced based on current log lag relative
to the snapshot threshold; reference LogSizePolicy and the cooldown/base
cooldown wording when making the change.
In `@d-engine-core/src/state_machine_handler/snapshot_policy/log_size.rs`:
- Around line 63-66: The cooldown timestamp (self.last_checked) is only updated
when should_trigger is true, so non-trigger checks bypass the cooldown; move the
store so last_checked.store(now, Ordering::Relaxed) is executed on every check
(i.e., unconditionally after computing should_trigger/lag/threshold) so the
"cooldown since last check" semantics are honored while preserving the existing
variables (self.last_checked, now, should_trigger, lag, threshold) and memory
ordering.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 503d70ec-a195-49af-91f2-9716f03f7b51
📒 Files selected for processing (2)
d-engine-core/src/config/raft.rsd-engine-core/src/state_machine_handler/snapshot_policy/log_size.rs
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Removed reference to adaptive cooldown which was evaluated but not implemented. The comment now accurately reflects the actual behavior: a fixed 60s cooldown reduced from the previous 3600s default.
What Does This PR Do?
Reduces the default
snapshot_cool_down_since_last_checkfrom 1 hour to 60 seconds,and applies three minor correctness fixes to
LogSizePolicyto make snapshottriggering reliable without requiring manual config tuning.
Type:
Why Is This Needed?
The default 3600s cooldown effectively disabled log compaction for typical workloads.
Even with
max_log_entries_before_snapshot = 1000, the cluster would wait 1 hourbetween snapshot evaluations, causing unbounded log growth, increasing startup memory
consumption, and degrading cluster lifetime performance. Users had to explicitly tune
the config to get reasonable behavior.
The three accompanying fixes address latent issues in
LogSizePolicy:now - lastcould underflow on clock jumps (replaced withsaturating_sub)Ordering::Acquireonlast_checkedload was heavier than needed; the CAS onis_checkingalready provides mutual exclusion, soRelaxedis correctwarn!when lag exceeds 10× threshold to surface misconfigured or stalledsnapshot pipelines before they become operational incidents
Checklist
Required:
make testpassesTesting
How tested:
log_size_test.rssuite (17 tests) — all passtest_learner_snapshot_concurrent_replication,test_leader_snapshot_concurrent_writes,test_follower_snapshot_generation_during_replication— all passFor bug fixes:
(
high_frequency_performanceandrespects_cooldown_periodexercise the fixed paths)Does This Follow d-engine's Principles?
Reviewer Notes
The adaptive cooldown proposed in PR #338 was evaluated but not included — it
introduced a regression where a below-threshold check would reset
last_checked,blocking subsequent detection of rapid log growth. The root cause analysis is
documented in the commit message. The three correctness fixes from #338 are applied
as-is; only the adaptive cooldown logic was dropped.
Estimated review complexity:
Summary by CodeRabbit
Configuration Changes
Observability Improvements
Optimizations