Skip to content

refactor(cluster): polish ember-cluster crate - #190

Merged
kacy merged 1 commit into
mainfrom
refactor/cluster-crate
Feb 19, 2026
Merged

refactor(cluster): polish ember-cluster crate#190
kacy merged 1 commit into
mainfrom
refactor/cluster-crate

Conversation

@kacy

@kacy kacy commented Feb 19, 2026

Copy link
Copy Markdown
Owner

summary

a focused cleanup of the four files most touched during phase 6.

message.rs

  • added ADDR_IPV4 / ADDR_IPV6 constants to replace bare 4/6 literals in the address encoder and decoder, and added inline comments explaining the byte-size checks
  • extracted a private encode_slice helper that handles the min(count, MAX_COLLECTION_COUNT) + write-u16-count + iterate pattern — this was repeated five times (encode_updates, Welcome, SlotsAnnounce, SlotsChanged arm, encode_member_info)
  • test .unwrap() calls on GossipMessage::decode replaced with .expect("roundtrip should succeed")

gossip.rs

  • check_probe_timeouts now uses a single retain pass to collect timed-out probes into two typed vecs, removing the prior collect-then-separate-remove pattern
  • the SlotsChanged arm and Welcome branch now clone the slot vec once into a named binding and reuse it, making the ownership path explicit
  • queue_vote_request / queue_vote_granted doc comments verified accurate

election.rs

  • collapsed the nested if/else in record_vote into a single assign-then-return

topology.rs

  • extracted ping_ms / pong_ms from the format! argument list in to_cluster_nodes_line so the call is easier to count
  • clarified the three mutation blocks in promote_replica with short comments describing the intent

lib.rs

  • rust,ignorerust,no_run in the crate-level example (compile-checked, not executed)

what was tested

cargo test -p ember-cluster — 95 tests pass, doc-test compiles

- 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
kacy merged commit 0845f49 into main Feb 19, 2026
4 of 7 checks passed
@kacy
kacy deleted the refactor/cluster-crate branch February 19, 2026 02:15
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
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