refactor(replication): extract helpers and simplify control flow - #192
Merged
Conversation
- 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
added a commit
that referenced
this pull request
Feb 19, 2026
refactor(replication): extract helpers and simplify control flow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
summary
cleanup pass on
replication.rsfollowing the phase 6 landing. nofunctional 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_taghelper — the pattern of reading a tag byte andreturning
InvalidDataif it doesn't match appeared four times insync()andhandle_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 eachiteration, 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 usingstr::to_ownedas a methodreference for the
Option<&str>→Option<String>step.expire_from_mshelper —if expire_ms > 0 { Some(Duration::from_millis(...)) } else { None }appeared three times. replaced with
bool::then, which is theidiomatic Rust spelling.
what was tested
cargo build -p ember-server— cleancargo test -p ember-server— 72/72 pass