Quick cache#7073
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughReplaces LRU-backed caches with a quick_cache-backed SizeTrackingCache (CLOCK-PRO), updates cache APIs and wrappers across the codebase, renames cache metrics, and migrates specialized caches (ZstdFrameCache, ForestCache, blockstore read cache) to the new engine. ChangesCache Engine Migration
Sequence DiagramsequenceDiagram
participant Caller
participant ForestCache
participant SizeTrackingCache
participant quick_cache
Caller->>ForestCache: get_or_else(key, compute_fn)
ForestCache->>SizeTrackingCache: get_or_compute(key, compute_fn)
alt Cache hit
SizeTrackingCache->>quick_cache: get(key)
quick_cache-->>SizeTrackingCache: Some(value)
SizeTrackingCache-->>ForestCache: (value, hit=true)
ForestCache->>ForestCache: increment TIPSET_HIT
else Cache miss
SizeTrackingCache->>SizeTrackingCache: call compute_fn()
SizeTrackingCache->>quick_cache: insert(key, value)
SizeTrackingCache-->>ForestCache: (value, hit=false)
ForestCache->>ForestCache: increment TIPSET_MISS
end
ForestCache-->>Caller: value
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
67eee27 to
6320b26
Compare
# Conflicts: # src/rpc/methods/eth.rs
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/utils/cache/size_tracking.rs (1)
116-126: 💤 Low valueConsider removing the unused
Option<V>return frompushfor clarity.All callers of
pushignore the return value. Since the method is documented as non-atomic (peek-then-insert pattern), returningOption<V>implies atomicity that doesn't exist. Changing the return type to()would accurately reflect actual usage:Simplify return type
- pub fn push(&self, k: K, v: V) -> Option<V> { - let prev = self.cache.peek(&k); - self.cache.insert(k, v); - prev + pub fn push(&self, k: K, v: V) { + self.cache.insert(k, v); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/utils/cache/size_tracking.rs` around lines 116 - 126, The push method currently returns Option<V> though all callers ignore it and the method is non-atomic; change pub fn push(&self, k: K, v: V) -> Option<V> to return () by removing the Option<V> return, eliminate the prev variable/peek return (just call self.cache.peek(&k) only if needed or remove the peek entirely if not needed), update the method body to perform self.cache.insert(k, v) and return nothing, and update the doc comment on push to remove references to returning a displaced value; keep references to push, cache.peek, and cache.insert when making these edits.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.config/lychee.toml:
- Around line 14-15: The exclusion currently uses the broad string "crates.io";
narrow it by removing the generic "crates.io" entry and instead add only the
specific failing URLs or path patterns that trigger bot protection (e.g., the
exact full URLs or host+path patterns supported by lychee) so real broken links
on crates.io are still caught; update the ignore list to reference those
explicit URL(s) or pattern(s) instead of the top-level "crates.io" token.
In `@src/db/car/mod.rs`:
- Around line 132-135: The current check in the cache insertion logic (using
entry_size.saturating_add(cache_key_size) >= self.max_size) rejects entries that
exactly equal the configured capacity; change the condition to use > instead of
>= so exact-fit entries are allowed (i.e. if
entry_size.saturating_add(cache_key_size) > self.max_size { return; }). Update
the comment to reflect that only items larger than the cache are skipped and
keep the saturating_add to avoid overflow; reference the variables entry_size,
cache_key_size and self.max_size in mod.rs.
---
Nitpick comments:
In `@src/utils/cache/size_tracking.rs`:
- Around line 116-126: The push method currently returns Option<V> though all
callers ignore it and the method is non-atomic; change pub fn push(&self, k: K,
v: V) -> Option<V> to return () by removing the Option<V> return, eliminate the
prev variable/peek return (just call self.cache.peek(&k) only if needed or
remove the peek entirely if not needed), update the method body to perform
self.cache.insert(k, v) and return nothing, and update the doc comment on push
to remove references to returning a displaced value; keep references to push,
cache.peek, and cache.insert when making these edits.
🪄 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: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: b8ce2083-98be-45fe-8d36-409bd7c825d0
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (22)
.config/lychee.tomlCHANGELOG.mdCargo.tomlsrc/beacon/drand.rssrc/chain/store/chain_store.rssrc/chain/store/index.rssrc/chain_sync/bad_block_cache.rssrc/db/blockstore_with_read_cache.rssrc/db/car/forest.rssrc/db/car/mod.rssrc/message_pool/msgpool/mod.rssrc/message_pool/msgpool/msg_pool.rssrc/message_pool/msgpool/selection.rssrc/message_pool/msgpool/utils.rssrc/metrics/mod.rssrc/rpc/methods/eth.rssrc/rpc/methods/f3.rssrc/state_manager/cache.rssrc/state_manager/mod.rssrc/state_migration/common/mod.rssrc/utils/cache/mod.rssrc/utils/cache/size_tracking.rs
# Conflicts: # src/message_pool/msgpool/mod.rs # src/message_pool/msgpool/msg_pool.rs # src/utils/cache/size_tracking.rs
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/utils/cache/size_tracking.rs (1)
208-237: 💤 Low valueInconsistent metric name prefixes.
The size metric includes a
cache_prefix (cache_{}_{}_size) whilelenandcapmetrics do not ({}_{}_len,{}_{}_cap). This naming inconsistency could make metric discovery and filtering more difficult for operators.♻️ Suggested fix for consistent naming
{ - let len_metric_name = format!("{}_{}_len", self.cache_name, self.cache_id); + let len_metric_name = format!("cache_{}_{}_len", self.cache_name, self.cache_id); let len_metric_help = format!("Length of cache {}_{}", self.cache_name, self.cache_id); ... } { - let cap_metric_name = format!("{}_{}_cap", self.cache_name, self.cache_id); + let cap_metric_name = format!("cache_{}_{}_cap", self.cache_name, self.cache_id); let cap_metric_help = format!("Capacity of cache {}_{}", self.cache_name, self.cache_id);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/utils/cache/size_tracking.rs` around lines 208 - 237, The len and cap metric names are missing the "cache_" prefix causing inconsistent metric naming; update len_metric_name and cap_metric_name to use the same "cache_{}_{}_len" and "cache_{}_{}_cap" format as size_metric_name, and adjust their help strings (len_metric_help and cap_metric_help) to reflect the "cache_{}_{}" prefix so all three metrics (size_metric_name, len_metric_name, cap_metric_name) consistently use the cache_ prefix and the same cache identifier formatting when encoded.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/utils/cache/size_tracking.rs`:
- Around line 208-237: The len and cap metric names are missing the "cache_"
prefix causing inconsistent metric naming; update len_metric_name and
cap_metric_name to use the same "cache_{}_{}_len" and "cache_{}_{}_cap" format
as size_metric_name, and adjust their help strings (len_metric_help and
cap_metric_help) to reflect the "cache_{}_{}" prefix so all three metrics
(size_metric_name, len_metric_name, cap_metric_name) consistently use the cache_
prefix and the same cache identifier formatting when encoded.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 95e60c01-4d17-4054-965f-ea30d9c4f341
📒 Files selected for processing (5)
src/message_pool/msgpool/msg_pool.rssrc/message_pool/msgpool/selection.rssrc/message_pool/msgpool/utils.rssrc/rpc/methods/eth.rssrc/utils/cache/size_tracking.rs
🚧 Files skipped from review as they are similar to previous changes (3)
- src/message_pool/msgpool/selection.rs
- src/message_pool/msgpool/utils.rs
- src/rpc/methods/eth.rs
Codecov Report❌ Patch coverage is Additional details and impacted files
... and 6 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Summary of changes
Changes introduced in this pull request:
Lruprefix. This is a breaking change for Prometheus metrics, but I doubt it's used by anyone. I added it in the CHANGELOG just in case.Reference issue to close (if applicable)
Closes
Other information and links
Change checklist
Outside contributions
Summary by CodeRabbit
Breaking Changes
Chores