refactor(cluster): polish ember-cluster crate - #190
Merged
Conversation
- message.rs: add ADDR_IPV4/ADDR_IPV6 constants, extract encode_slice
helper to de-dup the truncate+write-count+iterate pattern across five
encoding sites, add byte-size comments to the decode path, and
replace bare .unwrap() in tests with .expect("roundtrip should succeed")
- gossip.rs: collapse check_probe_timeouts to a single retain pass
with two collection vecs; fix double-clone in SlotsChanged arm and
Welcome branch to clone once and reuse the owned value
- election.rs: collapse nested if/else in record_vote to a single
assign-then-return
- topology.rs: lift ping_ms/pong_ms out of the format! call in
to_cluster_nodes_line; clarify promote_replica mutation comments
- lib.rs: use rust,no_run instead of rust,ignore in crate-level example
kacy
added a commit
that referenced
this pull request
Feb 19, 2026
cluster.rs:
- add ELECTION_STAGGER_MS, ELECTION_TIMEOUT_SECS, FAILOVER_GRACE_MS,
and REPLICATION_PORT_OFFSET constants to replace inline literals
- extract replication_port(data_port) helper used by both the
replication server and client; avoids repeating the three-step
checked_add arithmetic
- replace explicit drop(gossip)/drop(state) in save_config with
scoped blocks — idiomatic and signals clear intent
- unify raft_error_frame to build the message string first, then
wrap it in Frame::Error("ERR {msg}") — previously two arms used
.into() and one used format!()
- move PostAction enum definition outside the event loop; add a
comment explaining the deadlock-avoidance pattern
- replace 500/5/500 ms/s magic literals in start_election and
cluster_failover with the new constants
gossip.rs (follow-up to #190):
- restructure the SlotsChanged apply arm to use a bool flag so the
mutable borrow on `member` ends before the async emit call; this
removes the drop(member) reference warning emitted by rustc
kacy
added a commit
that referenced
this pull request
Feb 19, 2026
cluster.rs:
- add ELECTION_STAGGER_MS, ELECTION_TIMEOUT_SECS, FAILOVER_GRACE_MS,
and REPLICATION_PORT_OFFSET constants to replace inline literals
- extract replication_port(data_port) helper used by both the
replication server and client; avoids repeating the three-step
checked_add arithmetic
- replace explicit drop(gossip)/drop(state) in save_config with
scoped blocks — idiomatic and signals clear intent
- unify raft_error_frame to build the message string first, then
wrap it in Frame::Error("ERR {msg}") — previously two arms used
.into() and one used format!()
- move PostAction enum definition outside the event loop; add a
comment explaining the deadlock-avoidance pattern
- replace 500/5/500 ms/s magic literals in start_election and
cluster_failover with the new constants
gossip.rs (follow-up to #190):
- restructure the SlotsChanged apply arm to use a bool flag so the
mutable borrow on `member` ends before the async emit call; this
removes the drop(member) reference warning emitted by rustc
kacy
added a commit
that referenced
this pull request
Feb 19, 2026
- message.rs: add ADDR_IPV4/ADDR_IPV6 constants, extract encode_slice
helper to de-dup the truncate+write-count+iterate pattern across five
encoding sites, add byte-size comments to the decode path, and
replace bare .unwrap() in tests with .expect("roundtrip should succeed")
- gossip.rs: collapse check_probe_timeouts to a single retain pass
with two collection vecs; fix double-clone in SlotsChanged arm and
Welcome branch to clone once and reuse the owned value
- election.rs: collapse nested if/else in record_vote to a single
assign-then-return
- topology.rs: lift ping_ms/pong_ms out of the format! call in
to_cluster_nodes_line; clarify promote_replica mutation comments
- lib.rs: use rust,no_run instead of rust,ignore in crate-level example
kacy
added a commit
that referenced
this pull request
Feb 19, 2026
cluster.rs:
- add ELECTION_STAGGER_MS, ELECTION_TIMEOUT_SECS, FAILOVER_GRACE_MS,
and REPLICATION_PORT_OFFSET constants to replace inline literals
- extract replication_port(data_port) helper used by both the
replication server and client; avoids repeating the three-step
checked_add arithmetic
- replace explicit drop(gossip)/drop(state) in save_config with
scoped blocks — idiomatic and signals clear intent
- unify raft_error_frame to build the message string first, then
wrap it in Frame::Error("ERR {msg}") — previously two arms used
.into() and one used format!()
- move PostAction enum definition outside the event loop; add a
comment explaining the deadlock-avoidance pattern
- replace 500/5/500 ms/s magic literals in start_election and
cluster_failover with the new constants
gossip.rs (follow-up to #190):
- restructure the SlotsChanged apply arm to use a bool flag so the
mutable borrow on `member` ends before the async emit call; this
removes the drop(member) reference warning emitted by rustc
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
a focused cleanup of the four files most touched during phase 6.
message.rs
ADDR_IPV4/ADDR_IPV6constants to replace bare4/6literals in the address encoder and decoder, and added inline comments explaining the byte-size checksencode_slicehelper that handles themin(count, MAX_COLLECTION_COUNT)+ write-u16-count + iterate pattern — this was repeated five times (encode_updates, Welcome, SlotsAnnounce, SlotsChanged arm, encode_member_info).unwrap()calls onGossipMessage::decodereplaced with.expect("roundtrip should succeed")gossip.rs
check_probe_timeoutsnow uses a singleretainpass to collect timed-out probes into two typed vecs, removing the prior collect-then-separate-remove patternSlotsChangedarm andWelcomebranch now clone the slot vec once into a named binding and reuse it, making the ownership path explicitqueue_vote_request/queue_vote_granteddoc comments verified accurateelection.rs
if/elseinrecord_voteinto a single assign-then-returntopology.rs
ping_ms/pong_msfrom theformat!argument list into_cluster_nodes_lineso the call is easier to countpromote_replicawith short comments describing the intentlib.rs
rust,ignore→rust,no_runin the crate-level example (compile-checked, not executed)what was tested
cargo test -p ember-cluster— 95 tests pass, doc-test compiles