pub struct TokenRing<ElemT> { /* private fields */ }
Expand description
A token ring is a continuous hash ring. It defines association by hashing a key
onto the ring and then walking the ring in one direction.
Cassandra and Scylla use it for determining data ownership which allows for efficient load balancing.
The token ring is used by the driver to find the replicas for a given token.
Each ring member has a token (i64 number) which defines the member’s position on the ring.
The ring is circular and can be traversed in the order of increasing tokens.
TokenRing
makes it easy and efficient to traverse the ring starting at a given token.
Implementations§
source§impl<ElemT> TokenRing<ElemT>
impl<ElemT> TokenRing<ElemT>
sourcepub fn iter(&self) -> impl Iterator<Item = &(Token, ElemT)>
pub fn iter(&self) -> impl Iterator<Item = &(Token, ElemT)>
Iterates over all members of the ring starting at the lowest token.
sourcepub fn ring_range_full(
&self,
token: Token,
) -> impl Iterator<Item = &(Token, ElemT)>
pub fn ring_range_full( &self, token: Token, ) -> impl Iterator<Item = &(Token, ElemT)>
Provides an iterator over the ring members starting at the given token. The iterator traverses the whole ring in the direction of increasing tokens. After reaching the maximum token it wraps around and continues from the lowest one. The iterator visits each member once, it doesn’t have infinite length.
sourcepub fn ring_range(&self, token: Token) -> impl Iterator<Item = &ElemT>
pub fn ring_range(&self, token: Token) -> impl Iterator<Item = &ElemT>
Provides an iterator over the ring’s elements starting at the given token.
The iterator traverses the whole ring in the direction of increasing tokens.
After reaching the maximum token it wraps around and continues from the lowest one.
The iterator visits each member once, it doesn’t have an infinite length.
To access the token along with the element you can use ring_range_full
.
sourcepub fn get_elem_for_token(&self, token: Token) -> Option<&ElemT>
pub fn get_elem_for_token(&self, token: Token) -> Option<&ElemT>
Traverses the ring starting at the given token and returns the first ring member encountered.
Trait Implementations§
Auto Trait Implementations§
impl<ElemT> Freeze for TokenRing<ElemT>
impl<ElemT> RefUnwindSafe for TokenRing<ElemT>where
ElemT: RefUnwindSafe,
impl<ElemT> Send for TokenRing<ElemT>where
ElemT: Send,
impl<ElemT> Sync for TokenRing<ElemT>where
ElemT: Sync,
impl<ElemT> Unpin for TokenRing<ElemT>where
ElemT: Unpin,
impl<ElemT> UnwindSafe for TokenRing<ElemT>where
ElemT: UnwindSafe,
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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