pub struct Peer { /* private fields */ }Expand description
One peer in the cluster ring.
Implementations§
Source§impl Peer
impl Peer
Sourcepub fn new(
idx: u32,
endpoint: PeerEndpoint,
rack: String,
dc: String,
tokens: Vec<DynToken>,
is_local: bool,
is_same_dc: bool,
is_secure: bool,
) -> Self
pub fn new( idx: u32, endpoint: PeerEndpoint, rack: String, dc: String, tokens: Vec<DynToken>, is_local: bool, is_same_dc: bool, is_secure: bool, ) -> Self
Build a new peer record.
idx is the peer’s index in the pool’s peer array (0 is
always the local node). is_local and is_same_dc mirror
the reference engine’s flags. The initial state is
PeerState::Joining for the local node and
PeerState::Down for a remote one (the reference engine
optimistically waits for the first gossip ack before
promoting a remote peer).
§Examples
use dynomite::cluster::peer::{Peer, PeerEndpoint, PeerState};
use dynomite::hashkit::DynToken;
let p = Peer::new(
1,
PeerEndpoint::tcp("h".into(), 1),
"r".into(),
"d".into(),
vec![DynToken::from_u32(0)],
false,
true,
false,
);
assert_eq!(p.idx(), 1);
assert_eq!(p.state(), PeerState::Down);Sourcepub fn endpoint(&self) -> &PeerEndpoint
pub fn endpoint(&self) -> &PeerEndpoint
Endpoint reference.
Sourcepub fn is_same_dc(&self) -> bool
pub fn is_same_dc(&self) -> bool
True when the peer shares the local datacenter.
Sourcepub fn set_state(&mut self, state: PeerState, ts_secs: u64)
pub fn set_state(&mut self, state: PeerState, ts_secs: u64)
Update the lifecycle state. The supplied ts_secs mirrors
the reference engine’s gossip_node::ts and is used by the
failure detector to age the peer out.
§Examples
use dynomite::cluster::peer::{Peer, PeerEndpoint, PeerState};
use dynomite::hashkit::DynToken;
let mut p = Peer::new(
0, PeerEndpoint::tcp("h".into(), 1), "r".into(), "d".into(),
vec![DynToken::from_u32(0)], true, true, false,
);
p.set_state(PeerState::Normal, 42);
assert_eq!(p.state(), PeerState::Normal);
assert_eq!(p.last_state_ts_secs(), 42);Sourcepub fn last_state_ts_secs(&self) -> u64
pub fn last_state_ts_secs(&self) -> u64
Last observed gossip timestamp (epoch seconds).
Sourcepub fn record_failure(&mut self)
pub fn record_failure(&mut self)
Increment the consecutive-failure counter.
Sourcepub fn record_success(&mut self)
pub fn record_success(&mut self)
Reset the consecutive-failure counter.
Sourcepub fn failure_count(&self) -> u32
pub fn failure_count(&self) -> u32
Current consecutive-failure count.
Sourcepub fn failure_detector(&self) -> &PhiAccrual
pub fn failure_detector(&self) -> &PhiAccrual
Borrow the phi-accrual failure detector for this peer. Used by the gossip task to record heartbeat arrivals and to query the suspicion level on every tick.
Sourcepub fn failure_detector_mut(&mut self) -> &mut PhiAccrual
pub fn failure_detector_mut(&mut self) -> &mut PhiAccrual
Mutably borrow the phi-accrual failure detector. Use from the gossip / heartbeat task.
Sourcepub fn primary_token(&self) -> Option<&DynToken>
pub fn primary_token(&self) -> Option<&DynToken>
First (primary) token of this peer, if any.
§Examples
use dynomite::cluster::peer::{Peer, PeerEndpoint};
use dynomite::hashkit::DynToken;
let p = Peer::new(
0, PeerEndpoint::tcp("h".into(), 1), "r".into(), "d".into(),
vec![DynToken::from_u32(7)], true, true, false,
);
assert_eq!(p.primary_token().unwrap().get_int(), 7);Trait Implementations§
Auto Trait Implementations§
impl Freeze for Peer
impl RefUnwindSafe for Peer
impl Send for Peer
impl Sync for Peer
impl Unpin for Peer
impl UnsafeUnpin for Peer
impl UnwindSafe for Peer
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§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.