datum-cluster 0.10.1

Datum cluster membership over SWIM gossip
Documentation
use std::time::{Duration, SystemTime};

use crate::Member;

/// Pluggable policy that decides when an unreachable member is down.
///
/// v0.10 ships only timeout downing. Quorum and split-brain resolution
/// strategies belong in a later work package before placement relies on
/// automatic downing for singleton safety.
pub trait DowningProvider: Send + Sync + 'static {
    /// Human-readable provider name for diagnostics.
    fn name(&self) -> &'static str;

    /// Return `true` when `member` should transition to `Down`.
    fn should_down(&self, member: &Member, unreachable_for: Duration, now: SystemTime) -> bool;
}

/// Down a member after it has remained unreachable for a fixed timeout.
#[derive(Debug, Clone)]
pub struct TimeoutDowning {
    timeout: Duration,
}

impl TimeoutDowning {
    /// Create timeout downing with `timeout`.
    #[must_use]
    pub const fn new(timeout: Duration) -> Self {
        Self { timeout }
    }

    /// Configured unreachable timeout.
    #[must_use]
    pub const fn timeout(&self) -> Duration {
        self.timeout
    }
}

impl DowningProvider for TimeoutDowning {
    fn name(&self) -> &'static str {
        "timeout"
    }

    fn should_down(&self, _member: &Member, unreachable_for: Duration, _now: SystemTime) -> bool {
        unreachable_for >= self.timeout
    }
}