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);