Skip to content

tasteful refactoring — clarity, dedup, structure#94

Merged
kacy merged 6 commits intomainfrom
refactor/clarity-dedup-structure
Feb 12, 2026
Merged

tasteful refactoring — clarity, dedup, structure#94
kacy merged 6 commits intomainfrom
refactor/clarity-dedup-structure

Conversation

@kacy
Copy link
Copy Markdown
Owner

@kacy kacy commented Feb 12, 2026

summary

after three rounds of hardening, this is purely cosmetic: reducing duplication, improving organization, and making functions scannable. six independent changes, one per commit.

  • move capped_capacity to format.rs — identical function lived in both aof.rs and snapshot.rs, now shared from the format module
  • group aof tag constants by data type — 24 flat constants reordered into logical sections (string, list, sorted set, hash, set, key lifecycle, protobuf). values unchanged
  • extract read_string_list helper — ZREM, HDEL, SADD, SREM deserialization shared a read-count-then-loop-strings pattern. each call site shrinks from ~7 to ~3 lines
  • extract parse_snap_value — type-tag → SnapValue parsing duplicated between plaintext and encrypted snapshot paths. extracted the clean version for the encrypted path; plaintext stays inline (CRC buffer mirroring)
  • extract incr_result / write_result_len — IncrError and WriteError → ShardResponse conversion appeared 9 times identically in dispatch. helper functions replace 4-5 lines per site with 1
  • extract startup helpers from main.rsresolve_password(), parse_bind_addr(), build_persistence_config() pulled out so the startup flow reads at a glance

what was tested

  • cargo test -p emberkv-core -p ember-persistence -p ember-server -p ember-cluster -p ember-protocol — all pass
  • cargo clippy --workspace -- -D warnings — clean
  • cargo fmt --all -- --check — clean
  • verified with --features encryption builds

design considerations

  • left connection.rs execute() alone — 800 lines but each arm is self-contained and greppable. abstracting would obscure response patterns
  • left keyspace.rs entry lookup alone — ~40 occurrences but each has subtly different logic. a generic closure would hide important details
  • parse_snap_value gated behind #[cfg(feature = "encryption")] — only the encrypted read path uses it; plaintext path interleaves CRC buffer writes so can't share the function

kacy added 6 commits February 11, 2026 22:38
identical function defined in both aof.rs and snapshot.rs. now lives
in format.rs as a pub fn, both callers import from there.
24 flat constants reorganized into logical sections: string, list,
sorted set, hash, set, key lifecycle, protobuf. values unchanged.
ZREM, HDEL, SADD, and SREM all did identical work: read count, alloc
vec with capped capacity, loop read_string. shared helper replaces
~7 lines per call site with ~3.
type-tag → SnapValue parsing was duplicated between read_plaintext_entry
and read_encrypted_entry. extracted the clean version as parse_snap_value,
used in the encrypted path. plaintext path stays inline because it
interleaves CRC buffer mirroring.
incr_result() handles the IncrError → ShardResponse pattern (5 call
sites), write_result_len() handles WriteError → Len (4 call sites).
each call site shrinks from 4-5 lines to 1.
resolve_password(), parse_bind_addr(), and build_persistence_config()
pulled out of main() so the startup flow is scannable at a glance.
three bind-address parse blocks replaced with a shared helper.
@kacy kacy merged commit 003e30a into main Feb 12, 2026
5 of 7 checks passed
@kacy kacy deleted the refactor/clarity-dedup-structure branch February 12, 2026 03:48
kacy added a commit that referenced this pull request Feb 19, 2026
* refactor: move capped_capacity to shared format module

identical function defined in both aof.rs and snapshot.rs. now lives
in format.rs as a pub fn, both callers import from there.

* docs: group aof tag constants by data type

24 flat constants reorganized into logical sections: string, list,
sorted set, hash, set, key lifecycle, protobuf. values unchanged.

* refactor: extract read_string_list helper in aof deserialization

ZREM, HDEL, SADD, and SREM all did identical work: read count, alloc
vec with capped capacity, loop read_string. shared helper replaces
~7 lines per call site with ~3.

* refactor: extract parse_snap_value for encrypted snapshot reading

type-tag → SnapValue parsing was duplicated between read_plaintext_entry
and read_encrypted_entry. extracted the clean version as parse_snap_value,
used in the encrypted path. plaintext path stays inline because it
interleaves CRC buffer mirroring.

* refactor: extract incr/write error conversion helpers in shard dispatch

incr_result() handles the IncrError → ShardResponse pattern (5 call
sites), write_result_len() handles WriteError → Len (4 call sites).
each call site shrinks from 4-5 lines to 1.

* refactor: extract startup helpers from main

resolve_password(), parse_bind_addr(), and build_persistence_config()
pulled out of main() so the startup flow is scannable at a glance.
three bind-address parse blocks replaced with a shared helper.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant