Skip to main content

GossipHandler

Struct GossipHandler 

Source
pub struct GossipHandler { /* private fields */ }
Expand description

Authoritative owner of PeerState transitions for the gossip plane.

The handler holds an Arc<ServerPool> and feeds the per-peer phi-accrual failure detectors as gossip frames arrive. A periodic tick re-evaluates phi for every non-local peer and toggles PeerState between Normal and Down based on the configured threshold:

  • a peer is Normal once at least one heartbeat has been recorded AND phi(now) <= threshold,
  • a peer is Down when no heartbeat has ever been recorded OR phi(now) > threshold.

The handler is the single place that mutates peer.state once gossip is wired; the supervisor loop that owns the TCP link no longer publishes peer-state transitions of its own.

§Examples

use std::sync::Arc;
use dynomite::cluster::gossip::GossipHandler;
use dynomite::cluster::peer::{Peer, PeerEndpoint};
use dynomite::cluster::pool::{PoolConfig, ServerPool};
use dynomite::hashkit::DynToken;

let cfg = PoolConfig::default();
let local = Peer::new(
    0, PeerEndpoint::tcp("h".into(), 1), "r".into(), "d".into(),
    vec![DynToken::from_u32(0)], true, true, false,
);
let pool = Arc::new(ServerPool::new(cfg, vec![local]));
let handler = GossipHandler::new(pool);
assert!((handler.threshold() - 8.0).abs() < f64::EPSILON);

Implementations§

Source§

impl GossipHandler

Source

pub fn new(pool: Arc<ServerPool>) -> Self

Build a fresh handler over pool using the default phi-accrual threshold (crate::cluster::failure_detector::DEFAULT_THRESHOLD).

Source

pub fn with_failure_metrics(self, metrics: Arc<FailureMetrics>) -> Self

Attach a crate::stats::FailureMetrics handle.

When set, Self::evaluate emits a peer_state_transitions_total counter tick and a peer_state_current gauge update for every transition it applies, plus a gossip_phi_score gauge update for every non-local peer regardless of whether its state changed. Default behaviour is unchanged when no metrics handle is supplied.

Source

pub fn with_events(self, events: Arc<EventManager>) -> Self

Attach an EventManager handle.

When set, every peer-state transition the handler applies surfaces a ClusterEvent::PeerUp or ClusterEvent::PeerDown payload on the manager’s broadcast. Default behaviour is unchanged when no event manager is supplied.

Source

pub fn events(&self) -> Option<&Arc<EventManager>>

Borrow the installed event manager, if any.

Source

pub fn with_threshold(self, threshold: f64) -> Self

Override the phi threshold (default 8.0).

Source

pub fn with_interval(self, interval: Duration) -> Self

Override the gossip interval used by the periodic tick when the handler is driven by the binary’s run loop. The in-process tests do not depend on this value.

Source

pub fn threshold(&self) -> f64

Phi threshold the handler is configured with.

Source

pub fn interval(&self) -> Duration

Configured gossip interval.

Source

pub fn pool(&self) -> &Arc<ServerPool>

Borrow the underlying pool.

Source

pub fn record_heartbeat_pname(&self, pname: &str, now: Instant)

Record an inbound gossip heartbeat from the peer identified by pname (a host:port string matching the peer’s crate::cluster::peer::PeerEndpoint::pname).

Mutates the peer’s failure detector and immediately promotes the peer’s state to PeerState::Normal when phi(now) is below the threshold; this gives gossip a snappy first-contact transition without waiting for the next periodic tick.

Unknown pnames are ignored.

Source

pub fn record_heartbeat_idx(&self, peer_idx: u32, now: Instant)

Record an inbound gossip heartbeat against a known peer index. Used by tests and by callers that already resolved the originating peer.

Source

pub fn evaluate(&self, now: Instant) -> Vec<(u32, PeerState)>

Walk every non-local peer and reconcile its PeerState with the failure detector’s current view of phi(now). Returns the list of (peer_idx, new_state) transitions the call applied (handy in tests).

This is the failure-detector tick the binary runs on a periodic timer. Calling it never panics and it never blocks on I/O.

Source

pub fn mark_down_pname(&self, pname: &str)

Mark the peer identified by pname as PeerState::Down without consulting the failure detector. Used by the gossip-shutdown path so the dispatcher can short-circuit routing to a peer that announced its own departure.

Source

pub fn reset_detector(&self, peer_idx: u32)

Reset the per-peer failure detector. Used when a peer is removed and re-added so historical jitter does not bias the new suspicion value.

Trait Implementations§

Source§

impl Debug for GossipHandler

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,