Skip to content

refactor(server): clean up cluster.rs + fix gossip borrow warning - #191

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

refactor(server): clean up cluster.rs + fix gossip borrow warning#191
kacy merged 1 commit into
mainfrom
refactor/server-cluster

Conversation

@kacy

@kacy kacy commented Feb 19, 2026

Copy link
Copy Markdown
Owner

summary

a focused cleanup of cluster.rs now that the phase 6 failover and replication code has settled. also includes a small follow-up fix to gossip.rs (from #190) that rustc flagged.

cluster.rs

  • four named constants replace inline magic numbers: ELECTION_STAGGER_MS (500), ELECTION_TIMEOUT_SECS (5), FAILOVER_GRACE_MS (500), REPLICATION_PORT_OFFSET (2)
  • replication_port(data_port) helper centralizes the data + offset + 2 arithmetic that previously appeared inline in start_replication_server and start_replication_client
  • save_config drops the explicit drop(gossip) / drop(state) calls in favour of scoped blocks — the lock guard lifetimes are now obvious from structure alone
  • raft_error_frame builds the message string in a match, then wraps it once with Frame::Error(format!("ERR {msg}")) — previously two arms used .into() and one used format!() inconsistently
  • PostAction is defined once before the while let loop, not re-defined on each iteration; a comment explains the deadlock-avoidance pattern it implements
  • the start_election TODO-style comment is replaced with a short note explaining why a fixed stagger delay is used today and what the correct implementation would require

gossip.rs

the SlotsChanged arm now uses a should_emit: bool flag so the mutable borrow on member ends before the async self.emit call. this removes the drop(member) reference warning that rustc emitted after #190.

what was tested

cargo build -p ember-server — clean, no warnings
cargo test -p ember-server -p ember-cluster -p emberkv-core -p ember-persistence -p ember-protocol — all pass

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
kacy merged commit 03377f3 into main Feb 19, 2026
3 of 6 checks passed
@kacy
kacy deleted the refactor/server-cluster branch February 19, 2026 02:22
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