pub struct NodeRegistry { /* private fields */ }Expand description
Cluster membership store backed by a consistent hash ring.
Maintains a live map of NodeInfo and mirrors add/remove operations
into a ConsistentHashRing so routing decisions stay in sync.
Implementations§
Source§impl NodeRegistry
impl NodeRegistry
Sourcepub fn register(&mut self, info: NodeInfo)
pub fn register(&mut self, info: NodeInfo)
Register a node (or overwrite an existing entry with the same ID).
Sourcepub fn deregister(&mut self, node_id: &str)
pub fn deregister(&mut self, node_id: &str)
Remove a node from the registry and the hash ring.
Sourcepub fn mark_healthy(&mut self, node_id: &str, healthy: bool)
pub fn mark_healthy(&mut self, node_id: &str, healthy: bool)
Update the health status of a node.
If healthy is false the node is kept in the registry but excluded
from routing via route_request and healthy_nodes.
Sourcepub fn update_load(&mut self, node_id: &str, load: f32)
pub fn update_load(&mut self, node_id: &str, load: f32)
Update the load factor of a node. Clamped to [0.0, 1.0].
Sourcepub fn route_request(&self, request_key: &str) -> Option<&NodeInfo>
pub fn route_request(&self, request_key: &str) -> Option<&NodeInfo>
Route a request to a healthy node using consistent hashing.
Walks the ring starting at request_key’s hash position and returns
the first node that exists in the registry and is healthy.
Returns None if there are no healthy nodes.
Sourcepub fn healthy_nodes(&self) -> Vec<&NodeInfo>
pub fn healthy_nodes(&self) -> Vec<&NodeInfo>
Returns references to all healthy nodes (arbitrary order).
Sourcepub fn all_nodes(&self) -> Vec<&NodeInfo>
pub fn all_nodes(&self) -> Vec<&NodeInfo>
Returns references to all registered nodes (arbitrary order).
Sourcepub fn ring(&self) -> &ConsistentHashRing
pub fn ring(&self) -> &ConsistentHashRing
Expose a reference to the underlying ring (read-only).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for NodeRegistry
impl RefUnwindSafe for NodeRegistry
impl Send for NodeRegistry
impl Sync for NodeRegistry
impl Unpin for NodeRegistry
impl UnsafeUnpin for NodeRegistry
impl UnwindSafe for NodeRegistry
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