pub struct DistributedCoordinator { /* private fields */ }Expand description
In-memory multi-node coordinator.
Manages cluster topology, routes incoming requests to healthy nodes via consistent hashing, and exposes cluster health information.
Note: This implementation is intentionally in-memory only — no actual TCP connections are established. It is designed for unit testing and single-process simulation. Production deployments would wrap this with a gRPC/HTTP gossip layer.
Implementations§
Source§impl DistributedCoordinator
impl DistributedCoordinator
Sourcepub fn new(config: CoordinatorConfig) -> Self
pub fn new(config: CoordinatorConfig) -> Self
Create a new coordinator with the given configuration.
Does not automatically register self — call register_self to
add this node to the ring.
Sourcepub fn register_self(&mut self)
pub fn register_self(&mut self)
Register this node in the local registry so it participates in routing.
Sourcepub fn add_peer(&mut self, addr: &str, node_id: &str)
pub fn add_peer(&mut self, addr: &str, node_id: &str)
Add a peer to the registry as a healthy node with zero load.
addr is the peer’s "host:port" bind address.
node_id is the peer’s unique identifier.
Sourcepub fn route(&self, request_key: &str) -> Option<String>
pub fn route(&self, request_key: &str) -> Option<String>
Route request_key to a healthy node and return its address.
Returns None if no healthy nodes are available.
Sourcepub fn cluster_size(&self) -> usize
pub fn cluster_size(&self) -> usize
Total number of nodes registered in the cluster (healthy + unhealthy).
Sourcepub fn healthy_count(&self) -> usize
pub fn healthy_count(&self) -> usize
Number of nodes currently marked as healthy.
Sourcepub fn topology_summary(&self) -> String
pub fn topology_summary(&self) -> String
A human-readable summary of current cluster topology.
Format (not stable across versions):
cluster[nodes=3 healthy=2 vnodes=450 self=node-0]Sourcepub fn registry(&self) -> &NodeRegistry
pub fn registry(&self) -> &NodeRegistry
Access the underlying registry (read-only).
Sourcepub fn config(&self) -> &CoordinatorConfig
pub fn config(&self) -> &CoordinatorConfig
Access the coordinator config.
Sourcepub fn set_peer_health(&mut self, node_id: &str, healthy: bool)
pub fn set_peer_health(&mut self, node_id: &str, healthy: bool)
Mark a peer node as healthy or unhealthy.
Sourcepub fn update_peer_load(&mut self, node_id: &str, load: f32)
pub fn update_peer_load(&mut self, node_id: &str, load: f32)
Update a peer’s reported load factor.
Auto Trait Implementations§
impl Freeze for DistributedCoordinator
impl RefUnwindSafe for DistributedCoordinator
impl Send for DistributedCoordinator
impl Sync for DistributedCoordinator
impl Unpin for DistributedCoordinator
impl UnsafeUnpin for DistributedCoordinator
impl UnwindSafe for DistributedCoordinator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more