Skip to main content

SwimState

Struct SwimState 

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

The pure SWIM + Lifeguard state machine for one node.

Deterministic and I/O-free: every method takes a logical tick or an explicit event and returns the peer-state transitions to apply. See the module docs for the protocol and the two-layer rationale.

Implementations§

Source§

impl SwimState

Source

pub fn new(me: usize, n: usize, cfg: SwimConfig) -> Self

Build a state machine for node me in a group of n members. Every other member starts Status::Alive at incarnation 0 (the join-time optimistic assumption; a genuinely dead member is discovered by the first failed probe).

§Panics

Panics if me >= n; a node must be a member of its own group.

Source

pub fn me(&self) -> usize

This node’s own index.

Source

pub fn my_incarnation(&self) -> Incarnation

This node’s current incarnation.

Source

pub fn nack_score(&self) -> u32

Current Lifeguard nack score (0 means “I believe I am healthy”).

Source

pub fn status(&self, member: usize) -> Status

The internal SWIM status this node holds for member. Returns Status::Alive for me (a node always considers itself alive) and for any unknown index.

Source

pub fn incarnation(&self, member: usize) -> Incarnation

The incarnation this node holds for member.

Source

pub fn member_state(&self, member: usize) -> PeerState

Project the internal SWIM status onto the engine-wide PeerState the dispatcher consumes.

Mapping suspect to Down is deliberate: routing to a suspected-unreachable peer wastes a request, and a refutation promotes it straight back to Normal. The DST accuracy invariant is about the confirmed-dead status, not the transient suspect window.

Source

pub fn on_probe( &mut self, tick: Tick, target: usize, result: ProbeResult, ) -> Vec<(u32, PeerState)>

Record the outcome of a probe period initiated by this node against target at logical tick.

  • ProbeResult::Acked -> target confirmed alive; refresh its status and decay this node’s nack score.
  • ProbeResult::IndirectAcked -> target alive, but this node’s direct path failed: raise the nack score (Lifeguard self-awareness) and keep the target alive.
  • ProbeResult::Failed -> begin (or reinforce) suspicion of the target.

Returns any peer-state transitions the caller should apply.

Source

pub fn on_update(&mut self, tick: Tick, update: Update) -> Vec<(u32, PeerState)>

Merge an incoming membership update that piggybacked on ping / ack traffic. Returns any peer-state transitions.

The merge rule is the SWIM precedence order:

  • A higher incarnation always wins.
  • At equal incarnation, Dead beats Suspect beats Alive (a worse belief overrides a better one at the same incarnation, which is how a suspicion spreads).
  • An update about this node that suspects or kills it is refuted: this node bumps its own incarnation above the update and the refutation (a fresh Alive at the higher incarnation) is what the caller disseminates. Refutation is skipped when SwimConfig::refutation_enabled is false (negative-control only).
Source

pub fn tick(&mut self, tick: Tick) -> Vec<(u32, PeerState)>

Advance logical time to tick and confirm any suspicions whose (dogpile- and NS-adjusted) deadline has passed. Returns the peer-state transitions produced (suspect -> dead is not a PeerState change, since both map to Down; the list is non-empty only when a member first crosses into Down).

Source

pub fn confirm_deadline(&self, member: usize) -> Option<Tick>

The tick at which a suspicion of member will confirm dead, given the current suspector count and this node’s nack score. Returns None if the member is not currently suspect.

Source

pub fn snapshot(&self) -> Vec<(usize, PeerState)>

Snapshot every member’s projected PeerState, for the I/O shell to reconcile against the pool.

Trait Implementations§

Source§

impl Clone for SwimState

Source§

fn clone(&self) -> SwimState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SwimState

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<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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