Skip to content

refactor(replication): extract helpers and simplify control flow - #192

Merged
kacy merged 1 commit into
mainfrom
refactor/replication
Feb 19, 2026
Merged

refactor(replication): extract helpers and simplify control flow#192
kacy merged 1 commit into
mainfrom
refactor/replication

Conversation

@kacy

@kacy kacy commented Feb 19, 2026

Copy link
Copy Markdown
Owner

summary

cleanup pass on replication.rs following the phase 6 landing. no
functional changes — same wire protocol, same semantics throughout.

framed I/O primitives comment — adds a short section header above
the eight byte-level read/write helpers so readers immediately
understand they're looking at thin wrappers, not business logic.

expect_tag helper — the pattern of reading a tag byte and
returning InvalidData if it doesn't match appeared four times in
sync() and handle_replica(). extracted once, used everywhere.

snapshot buffer reuse — the sync loop previously allocated a fresh
Vec<u8> per shard. a single buffer, cleared and resized each
iteration, removes one heap allocation per shard on initial sync.

nested if-let flattened — the incremental-apply path had three
levels of if let. reduced by one using str::to_owned as a method
reference for the Option<&str>Option<String> step.

expire_from_ms helperif expire_ms > 0 { Some(Duration::from_millis(...)) } else { None }
appeared three times. replaced with bool::then, which is the
idiomatic Rust spelling.

what was tested

  • cargo build -p ember-server — clean
  • cargo test -p ember-server — 72/72 pass

- add a framed I/O primitives section comment above the byte-level
  read/write helpers so their purpose is immediately clear
- extract expect_tag() to de-dup the read-then-validate-tag pattern
  that appeared four times in sync() and handle_replica()
- reuse a single snap_buf across the shard loop to avoid one heap
  allocation per shard during initial sync
- flatten the nested if-let in the incremental-apply path and use
  str::to_owned as a method reference for clarity
- extract expire_from_ms() using bool::then to eliminate the verbose
  if expire_ms > 0 { Some(...) } else { None } pattern (appeared 3x)
@kacy
kacy merged commit 16dd3ed into main Feb 19, 2026
4 of 7 checks passed
@kacy
kacy deleted the refactor/replication branch February 19, 2026 02:26
kacy added a commit that referenced this pull request Feb 19, 2026
refactor(replication): extract helpers and simplify control flow
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