Skip to content

Commit 20cfd37

Browse files
authored
Fix/various bugs found (#21)
* Add regression tests for cache policies to ensure capacity-0 behavior - Introduced regression tests across multiple cache policies (ARC, MFU, MRU, SLRU, TwoQ) to verify that caches with a capacity of 0 correctly reject inserts and maintain expected behavior. - Added a new integration test file for cross-policy invariants to ensure consistent handling of capacity-0 across different cache implementations. - Updated the tests README to include information about the new invariant tests, enhancing documentation clarity. * Implement LRU eviction method and refine cache policies - Added `evict_lru` method to the ghost list for removing the least recently used key, enhancing eviction capabilities. - Updated ARC and other policies to utilize the new LRU eviction method, ensuring efficient capacity management. - Refined handling of capacity checks in various policies to prevent unnecessary evictions and improve performance. - Adjusted tests to validate the new eviction behavior and ensure consistency across cache implementations. * Refactor ClockRing documentation and enhance API usability - Updated operation table in `clock_ring.rs` to use links for method references, improving clarity and navigation. - Changed `HashMap` to `FxHashMap` in documentation for better performance context. - Added `Clone` derive to `Entry` and `ClockRing` structs to enhance usability in concurrent scenarios. - Modified public API methods to accept borrowed keys, allowing for more flexible key types and reducing unnecessary clones. - Improved documentation with concise examples for `clear`, `clear_shrink`, and `approx_bytes` methods, enhancing user understanding. * Update ClockRing documentation for improved clarity and usability - Changed `HashMap` to `FxHashMap` in the documentation to reflect performance optimizations. - Enhanced entry and ClockRing struct documentation to clarify key borrowing capabilities. - Added details on lookup methods accepting borrowed keys, improving API usability. - Updated examples and descriptions to align with recent changes in the public API. * Add iterators to ClockRing for enhanced usability - Introduced `Iter`, `IterMut`, `Keys`, `Values`, and `ValuesMut` iterators to `ClockRing`, allowing for flexible and efficient iteration over entries, keys, and values. - Updated documentation to include new iterator methods and examples, improving clarity and user guidance. - Enhanced the operation table to reflect the addition of iteration capabilities, ensuring comprehensive API coverage. * Fix concurrency issues and enhance cache policies - Resolved TOCTOU race conditions in `ConcurrentSlabStore` by consolidating `RwLock`s for atomicity during updates and removals. - Fixed ARC ghost-list directory leak to maintain invariant bounds during eviction. - Updated capacity handling in `Clock`, `ClockPro`, and `NRU` policies to reject zero capacity inserts gracefully. - Unified `CoreCache::insert` behavior across `MRU`, `SLRU`, and `TwoQ` policies for consistency. - Added metrics tracking for `ConcurrentWeightStore` operations. - Introduced new `GhostList::evict_lru()` method and iterators for `ClockRing`, along with integration tests for concurrency and policy invariants. - Updated `ClockRing` documentation with improved clarity and expanded operations table.
1 parent a72fd3c commit 20cfd37

17 files changed

Lines changed: 1642 additions & 222 deletions

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
- **ConcurrentSlabStore TOCTOU race conditions** — Separate `RwLock`s for index, entries, and free list allowed data corruption on concurrent update-after-remove, capacity overshoot under parallel inserts, and inconsistent reads during `clear()`. Consolidated into a single `SlabInner` behind one `RwLock` for full mutation atomicity.
12+
- **ARC ghost-list directory leak** — Case 4 (complete miss) did not prune ghost lists B1/B2, violating the paper's invariant that T1+T2+B1+B2 ≤ 2×capacity. Fixed to match the original ARC eviction logic.
13+
- **Capacity-0 coercion in Clock, ClockPro, NRU** — Constructors silently coerced `capacity=0` to 1 via `.max(1)`, inconsistent with other policies. Now honors zero capacity and rejects inserts gracefully.
14+
- **MFU insert return value at capacity 0**`MfuCore::insert` returned `Some(value)` for rejected inserts instead of `None`.
15+
- **MRU / SLRU / TwoQ `CoreCache::insert` inconsistency** — Trait impl duplicated update logic that diverged from the inherent method. Unified by delegating the trait impl to the inherent `insert`, which now returns `Option<V>`.
16+
- **ConcurrentWeightStore missing metrics**`try_insert` and `remove` did not update insert/update/remove counters.
17+
18+
### Added
19+
- `GhostList::evict_lru()` for popping the least-recently-used ghost entry.
20+
- `ClockRing` iterators: `Iter`, `IterMut`, `IntoIter`, `Keys`, `Values`, `ValuesMut`.
21+
- Integration test suite `tests/slab_concurrency.rs` for ConcurrentSlabStore race conditions and atomicity.
22+
- Integration test suite `tests/policy_invariants.rs` for cross-policy capacity-0 semantics.
23+
- Per-policy regression tests for capacity-0 behavior, insert return values, ARC ghost-list bounds, and ConcurrentWeightStore metrics.
24+
25+
### Changed
26+
- `ClockRing` module documentation updated with rustdoc intra-doc links and expanded operations table.
27+
1028
## [0.4.0] - 2026-02-18
1129

1230
### Added

0 commit comments

Comments
 (0)