Skip to main content

datum_cluster/
downing.rs

1use std::time::{Duration, SystemTime};
2
3use crate::Member;
4
5/// Pluggable policy that decides when an unreachable member is down.
6///
7/// v0.10 ships only timeout downing. Quorum and split-brain resolution
8/// strategies belong in a later work package before placement relies on
9/// automatic downing for singleton safety.
10pub trait DowningProvider: Send + Sync + 'static {
11    /// Human-readable provider name for diagnostics.
12    fn name(&self) -> &'static str;
13
14    /// Return `true` when `member` should transition to `Down`.
15    fn should_down(&self, member: &Member, unreachable_for: Duration, now: SystemTime) -> bool;
16}
17
18/// Down a member after it has remained unreachable for a fixed timeout.
19#[derive(Debug, Clone)]
20pub struct TimeoutDowning {
21    timeout: Duration,
22}
23
24impl TimeoutDowning {
25    /// Create timeout downing with `timeout`.
26    #[must_use]
27    pub const fn new(timeout: Duration) -> Self {
28        Self { timeout }
29    }
30
31    /// Configured unreachable timeout.
32    #[must_use]
33    pub const fn timeout(&self) -> Duration {
34        self.timeout
35    }
36}
37
38impl DowningProvider for TimeoutDowning {
39    fn name(&self) -> &'static str {
40        "timeout"
41    }
42
43    fn should_down(&self, _member: &Member, unreachable_for: Duration, _now: SystemTime) -> bool {
44        unreachable_for >= self.timeout
45    }
46}