pub struct ConsistentHashRing { /* private fields */ }Expand description
A consistent hash ring for stable shard-to-node assignment.
Each physical node is represented by replicas_per_node virtual nodes
spread across the ring. Adding or removing a node only relocates
1 / N of the shards on average.
Implementations§
Source§impl ConsistentHashRing
impl ConsistentHashRing
Sourcepub fn new(replicas_per_node: u32) -> Self
pub fn new(replicas_per_node: u32) -> Self
Create a new ring with replicas_per_node virtual nodes per physical node.
Sourcepub fn remove_node(&mut self, node_id: &str)
pub fn remove_node(&mut self, node_id: &str)
Remove a node from the ring.
Sourcepub fn get_node(&self, key: &ShardKey) -> Option<&str>
pub fn get_node(&self, key: &ShardKey) -> Option<&str>
Find the responsible node for a shard key.
Returns None if the ring is empty.
Sourcepub fn virtual_node_count(&self) -> usize
pub fn virtual_node_count(&self) -> usize
Return the number of virtual nodes (tokens) currently in the ring.
Sourcepub fn physical_node_count(&self) -> usize
pub fn physical_node_count(&self) -> usize
Return the number of distinct physical nodes in the ring.
Trait Implementations§
Source§impl Debug for ConsistentHashRing
impl Debug for ConsistentHashRing
Source§impl Default for ConsistentHashRing
impl Default for ConsistentHashRing
Source§fn default() -> ConsistentHashRing
fn default() -> ConsistentHashRing
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ConsistentHashRing
impl RefUnwindSafe for ConsistentHashRing
impl Send for ConsistentHashRing
impl Sync for ConsistentHashRing
impl Unpin for ConsistentHashRing
impl UnsafeUnpin for ConsistentHashRing
impl UnwindSafe for ConsistentHashRing
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
Mutably borrows from an owned value. Read more
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request