Skip to main content

FailureDetector

Struct FailureDetector 

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

Heartbeat-based failure detector.

Tracks node health via heartbeat messages and detects failures.

Implementations§

Source§

impl FailureDetector

Source

pub fn new() -> Self

Create a new failure detector with default config

Source

pub fn with_config(config: FailureDetectorConfig) -> Self

Create with custom config

Source

pub fn on_failure<F>(self, f: F) -> Self
where F: Fn(u64) + Send + Sync + 'static,

Set failure callback

Source

pub fn on_recovery<F>(self, f: F) -> Self
where F: Fn(u64) + Send + Sync + 'static,

Set recovery callback

Source

pub fn heartbeat(&self, node_id: u64, addr: SocketAddr)

Record a heartbeat from a node

Previously the recovery callback was invoked inside entry().and_modify(...), which holds the DashMap shard’s write lock. A user-supplied callback that re-entered the same shard (or any structure ordered against it) deadlocked; even without deadlock, every concurrent heartbeat hashing to the same shard stalled while the callback ran. The fix collects a “should I notify?” flag inside the closure and fires the callback after the and_modify returns, releasing the shard lock.

Source

pub fn check_all(&self) -> Vec<u64>

Check all nodes for failures

Callbacks are now invoked after the iter_mut loop has dropped its shard locks. Previously cb(*entry.key()) ran inside the iteration, with the per-shard write lock still held — a user-supplied callback that touched another DashMap entry on the same shard (or re-entered the failure detector itself via heartbeat / status) would deadlock. We collect the failed ids first, release the iteration locks, then fire the callbacks.

Source

pub fn status(&self, node_id: u64) -> NodeStatus

Get node status

Source

pub fn failed_nodes(&self) -> Vec<u64>

Get all failed nodes

Source

pub fn suspected_nodes(&self) -> Vec<u64>

Get all suspected nodes

Source

pub fn healthy_nodes(&self) -> Vec<u64>

Get all healthy nodes

Source

pub fn remove(&self, node_id: u64)

Remove a node from tracking

Source

pub fn cleanup(&self) -> usize

Clean up stale entries (nodes that have been failed for too long)

Source

pub fn stats(&self) -> FailureStats

Get statistics

nodes_tracked reads the O(1) counter; the per-status tally is still a single pass over the entries. That scan is observability-only (not on any hot path) and is deliberately NOT replaced by per-status counters: node status is mutated in-place via get_mut().status = ... in tests and could be elsewhere, which would silently drift maintained counters. The scan is always exact.

Source

pub fn node_count(&self) -> usize

Get node count

Trait Implementations§

Source§

impl Default for FailureDetector

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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<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