Skip to content

refactor(cluster): extract emit helper, add NodeId::as_key, clarify format_flags - #166

Merged
kacy merged 1 commit into
mainfrom
refactor/idiomatic-rust-pass-pr4
Feb 17, 2026
Merged

refactor(cluster): extract emit helper, add NodeId::as_key, clarify format_flags#166
kacy merged 1 commit into
mainfrom
refactor/idiomatic-rust-pass-pr4

Conversation

@kacy

@kacy kacy commented Feb 17, 2026

Copy link
Copy Markdown
Owner

summary

three targeted changes across ember-cluster to eliminate repeated patterns and clarify non-obvious design decisions.

gossip.rsemit helper

event_tx.send(...).await with error handling appeared 6 times in apply_updates and mark_alive. The patterns were inconsistent: MemberAlive, MemberFailed, and MemberLeft logged warnings on channel close, but MemberJoined and MemberSuspected were fire-and-forget (let _ = ...). This inconsistency had no intentional basis.

Extracted async fn emit(&self, event: GossipEvent) that sends and warns when the channel is closed (which only happens during shutdown or if the event consumer has a bug). All 6 call sites now behave consistently. Also added a comment on queue_update explaining why dropping oldest updates on overflow is safe: gossip convergence doesn't require every update to be delivered — members re-gossip state on each protocol period.

topology.rs + raft.rsNodeId::as_key()

node_id.0.to_string() appeared 7 times in apply_command (raft.rs). This accesses the inner UUID by tuple field index, which is opaque and could be confused with NodeId::to_string() (which only shows 8 chars via Display). Added pub(crate) fn as_key(&self) -> String on NodeId that makes the intent explicit — full UUID for use as a storage key — and replaced all 7 call sites.

topology.rsformat_flags comment

ClusterNode::format_flags() and NodeFlags::Display overlap but differ in two ways: role (master/slave) is included in format_flags but is not a flag, and pfail renders as fail? in format_flags per the Redis cluster protocol spec. Without a comment, these look like they should be deduplicated but can't be without breaking the wire format.

what was tested

  • cargo build -p ember-cluster — clean
  • cargo test -p ember-cluster — 63 tests pass, 0 failures
  • cargo fmt --check -p ember-cluster — no formatting issues

…ormat_flags

gossip.rs
- extract `async fn emit(&self, event: GossipEvent)` that sends on event_tx
  and warns when the channel is closed. replaces 6 copies of the inline
  send-and-check pattern in apply_updates and mark_alive. MemberJoined and
  MemberSuspected were previously fire-and-forget (let _ = ...); they now
  consistently warn on channel closure like the other events.
- add comment to queue_update explaining why dropping the oldest pending
  updates is safe (convergence doesn't require every update to be delivered).

topology.rs
- add NodeId::as_key() returning the full UUID string for use as a map key.
  NodeId::Display intentionally shows only 8 chars for readability, which
  is too short to use as a unique key in storage.
- add doc comment to format_flags explaining the two intentional divergences
  from NodeFlags::Display: role is included, and pfail renders as "fail?"
  per the Redis cluster protocol spec rather than "pfail".

raft.rs
- replace node_id.0.to_string() with node_id.as_key() throughout apply_command.
  the UUID string access is now named rather than relying on tuple field indexing.
@kacy
kacy merged commit 403e62e into main Feb 17, 2026
7 checks passed
@kacy
kacy deleted the refactor/idiomatic-rust-pass-pr4 branch February 17, 2026 23:38
kacy added a commit that referenced this pull request Feb 19, 2026
…ormat_flags (#166)

gossip.rs
- extract `async fn emit(&self, event: GossipEvent)` that sends on event_tx
  and warns when the channel is closed. replaces 6 copies of the inline
  send-and-check pattern in apply_updates and mark_alive. MemberJoined and
  MemberSuspected were previously fire-and-forget (let _ = ...); they now
  consistently warn on channel closure like the other events.
- add comment to queue_update explaining why dropping the oldest pending
  updates is safe (convergence doesn't require every update to be delivered).

topology.rs
- add NodeId::as_key() returning the full UUID string for use as a map key.
  NodeId::Display intentionally shows only 8 chars for readability, which
  is too short to use as a unique key in storage.
- add doc comment to format_flags explaining the two intentional divergences
  from NodeFlags::Display: role is included, and pfail renders as "fail?"
  per the Redis cluster protocol spec rather than "pfail".

raft.rs
- replace node_id.0.to_string() with node_id.as_key() throughout apply_command.
  the UUID string access is now named rather than relying on tuple field indexing.
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