refactor: improve SCAN iterator/expiration performance - #8297
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
PR Summary by QodoOptimize SCAN iteration and expiration handling
AI Description
Diagram
High-Level Assessment
Files changed (4)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can turn these tips off under Display preferences Powered by Qodo |
🤖 Augment PR SummarySummary: This PR streamlines SCAN’s key iteration and lazy expiration path to reduce overhead during traversal. Changes:
Technical Notes: The existing journal flush guard maintains raw-iterator safety while expired entries are removed during SCAN. 🤖 Was this summary useful? React with 👍 or 👎 |
There was a problem hiding this comment.
🟢 Approval recommended
The refactor is localized, preserves prior expiration gating (including replica behavior), and the SCAN traversal preemption constraints remain enforced by the existing guards.
Pull request overview
This PR refactors the SCAN traversal/expiration path to avoid extra iterator wrapping and redundant expiration checks, improving hot-path performance while preserving existing expiration behavior.
Changes:
- Add
CompactKey::IsExpired(now_ms)for a fast inline expiration check on TTL-tagged keys. - Split
DbSlice::ExpireIfNeededlogic by extractingDbSlice::Expire(...)and addDbSlice::TryExpire(...)for safe “erase-if-expired” use with rawPrimeIterators. - Refactor SCAN callback to use
TryExpireand a small helper (AppendScanKey) to avoid extra work when matching/serializing keys.
File summaries
| File | Description |
|---|---|
| src/server/generic_family.cc | SCAN callback now uses raw iterators + TryExpire and centralizes key append/match logic. |
| src/server/db_slice.h | Adds TryExpire and factors out Expire(...) declaration used by expiration paths. |
| src/server/db_slice.cc | Refactors ExpireIfNeeded to use IsExpired + extracted Expire(...) implementation. |
| src/core/compact_object.h | Adds CompactKey::IsExpired(now_ms) helper used by expiration logic. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
e0bcc55 to
ce2ec18
Compare
There was a problem hiding this comment.
🟢 Approval recommended
Only a non-blocking test-coverage nit remains.
Review details
Suppressed comments (1)
src/server/generic_family.cc:670
- This changes SCAN to delete expired entries through a raw
PrimeIterator, but the existing SCAN tests cover live-key filtering/cursor mutation and do not exercise this expiration path. Please add a regression test that scans after TTL expiry (including a filtered scan and traversal past deleted entries) and verifies the expired key is removed without skipped/duplicate results; this is the behavior that protects the raw-iterator refactor.
if (db_slice.TryExpire(op_args.db_cntx, prime_it)) [[unlikely]]
return false;
- Files reviewed: 4/4 changed files
- Comments generated: 0 new
- Review effort level: Lite
Summary: This PR streamlines SCAN’s key iteration and lazy expiration path to reduce overhead during traversal.
Changes:
Technical Notes: The existing journal flush guard maintains raw-iterator safety while expired entries are removed during SCAN.
******k*I've asked AI to generate a call stack picture to show the difference in approaches for better understanding