refactor(storage): split db.rs into a directory module — mod/hash_ttl/kv_ops/accessors#403
Conversation
…/kv_ops/accessors db.rs had grown to 3113 lines against the repo's 1500-line file-size rule. The W5 typed-accessor unification (#400) concentrated the accessor matrix into three generics, which made the module's internal seams clean enough for a mechanical split: - db/mod.rs (1152 lines): Database struct, listpack/intset constants, per-element cost functions, HashTtlCond/FieldState/WrongType, ctor/clock methods, O(1) memory accounting, Default impl, and the whole test module (tests stay in mod.rs per repo convention). - db/hash_ttl.rs (476): HEXPIRE-family per-field TTL storage primitives (hash_set_field_ttl .. cleanup_empty_hash). - db/kv_ops.rs (833): core keyspace ops — get/set/remove families, lazy expiry, cold-tier promotion/read-through, scan/keys/random_key, expiry bookkeeping, versioning/LRU touch. - db/accessors.rs (701): W5 ValueKind/OwnedKind generic skeletons, per-type thin delegators, bespoke intset/listpack accessors, read-only ref accessors, blocking-wakeup list/zset helpers, streams. Pure code motion: every method body moved verbatim; public paths are unchanged (storage::db::Database and the cost fns resolve exactly as before; submodules only add inherent impl blocks). The only signature changes are visibility: check_expired / is_expired / wrongtype_error / cold_contains_alive / cold_read_only became pub(super) so sibling files and mod.rs tests keep access. Submodule files use crate:: imports per the module-structure convention. Gates: lib suite 4427 green (identical count to pre-split main); clippy -D warnings clean on default and tokio,jemalloc feature sets; fmt; VM Linux lib green on both runtimes. author: Tin Dang
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? |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughThe database implementation is reorganized into ChangesDatabase storage implementation
Estimated code review effort: 5 (Critical) | ~120 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant Database
participant ColdIndex
participant ColdDisk
Client->>Database: Read key
Database->>ColdIndex: Check cold location and TTL
ColdIndex-->>Database: Return location
Database->>ColdDisk: Read cold value
ColdDisk-->>Database: Return decoded value
Database->>ColdIndex: Revalidate and update cold state
Database-->>Client: Return value or absence
Possibly related PRs
✨ 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 |
…L fidelity (#404) Patch release rolling up the storage-unification stacked train (#396–#401) and the follow-up db.rs directory split (#403). Correctness: millisecond-TTL keys no longer expire up to 999 ms early (CompactEntry stored expiry as ms/1000-floored seconds; now absolute Unix ms end-to-end, exact PTTL readback, exact-ms RDB round-trips). Unification (behavior-preserving, pinned by golden byte-spec tests): one value codec behind RDB/spill/kv_serde with fail-closed corrupt decode + DoS count guards on every path; one spill pipeline — sync eviction batches victims into shared files (~N/256 manifest fsyncs instead of N per-key) and retains unserializable victims fail-closed; one eviction entry point (evict_to_budget + EvictionRun/EvictionSink, was 13 variants / 5 reclaim-loop copies); one typed-accessor skeleton (storage::db_kind static-dispatch markers); AofShardManifest rename; db.rs split into db/{mod,hash_ttl,kv_ops,accessors}.rs. Validation: same-VM A/B v0.8.1-vs-main — p=1 parity-or-better, eviction-plain faster every paired round, spill +3%, p=16 within noise. Release gate: crash-matrix nightly full matrix + ITERS=20 soak dispatched on the RC, green before tag (soak-first-then-tag). Rolls CHANGELOG [Unreleased] into [0.8.2], bumps Cargo.toml/lock, adds the RELEASES.md row, updates the README milestone table. author: Tin Dang
What
db.rs(3113 lines, vs the repo's 1500-line rule) becomes a directory module:db/mod.rsDatabasestruct, constants, cost fns,HashTtlCond/FieldState/WrongType, ctor/clock, memory accounting,Default, all testsdb/kv_ops.rsdb/accessors.rsValueKind/OwnedKindgenerics, per-type delegators, intset/listpack bespoke accessors, read-only refs, blocking-hook helpers, streamsdb/hash_ttl.rsWhy now
The W5 typed-accessor unification (#400) concentrated the accessor matrix into three generics, leaving clean seams. Follow-up flagged at campaign close.
Invariants
impl Databaseblocks;pub usere-exports untouched).check_expired/is_expired/wrongtype_error/cold_contains_alive/cold_read_only→pub(super)(cross-file access within the module tree).crate::imports; tests stay inmod.rs— both per the CLAUDE.md module-structure convention.Gates
-D warningsclean on both feature sets; fmt clean; CHANGELOG entry addedSummary by CodeRabbit
New Features
Bug Fixes