perf(storage): volatile-ttl evicts the exact nearest-expiry victim via the expiry index (#551) - #555
Conversation
…a the expiry index (#551) The volatile-ttl eviction policy sampled maxmemory-samples random volatile keys and evicted the sample's minimum expiry — an approximation that could miss the globally soonest key entirely (with 5 samples over 5,001 volatile keys, the true nearest-deadline key is picked ~0.1% of the time), evicting a key hours from expiring while one expiring in seconds survived to expire naturally moments later, wasting the eviction. The #541 deadline-ordered expiry index already holds every hot volatile key sorted by (expires_at_ms, key), so the exact answer is the index head: - Database::peek_nearest_expiry() — first index pair regardless of due-ness, O(log n); None when no hot key is volatile. Cold-spilled keys are not indexed, matching the old sampler which also only saw hot entries. - find_victim_volatile_ttl(db) drops the samples parameter and returns the index head's key. maxmemory-samples still governs the LRU/LFU/ random sampling policies, which are unchanged. Red/green: new test volatile_ttl_evicts_globally_nearest_expiry buries one now+60s key among 5,000 keys expiring in an hour — red under the sampling picker (probabilistically guaranteed miss), green on the index head. Eviction module 42/42, full host lib suite 4688/4688, clippy -D warnings clean. Closes #551 author: Tin Dang
|
ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthrough
ChangesVolatile-TTL eviction
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This PR changes volatile-TTL eviction to select the nearest-expiry key directly and reports passing targeted and full-suite validation. No actionable merge-blocking risk remains beyond normal checks and review. Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
Summary
volatile-ttleviction picked its victim by samplingmaxmemory-samplesrandom volatile keys and evicting the sample's minimum expiry — an approximation that can miss the globally soonest key entirely. With 5 samples over 5,001 volatile keys the true nearest-deadline key is chosen ~0.1% of the time: the policy evicts a key hours from expiring while one expiring in seconds survives, expires naturally moments later, and the eviction is wasted.The #541 deadline-ordered expiry index already holds every hot volatile key sorted by
(expires_at_ms, key), so the exact answer is the index head:Database::peek_nearest_expiry()— first index pair regardless of due-ness, O(log n);Nonewhen no hot key is volatile. Cold-spilled keys are not indexed, matching the old sampler which also only saw hot entries.find_victim_volatile_ttl(db)drops thesamplesparameter and returns the index head's key.maxmemory-samplesstill governs LRU/LFU/random, which remain sampling-based.Red/green
New test
volatile_ttl_evicts_globally_nearest_expiryburies onenow+60skey among 5,000 keys expiring in an hour — red under the sampling picker (probabilistically guaranteed miss), green on the index head.Validation
-D warningsclean, fmt clean, host audits greenCloses #551
Summary by CodeRabbit
Bug Fixes
volatile-ttleviction to consistently remove the volatile key with the nearest expiration time.maxmemory-samplesbehavior for LRU, LFU, and random eviction policies.Documentation