Skip to content

Commit 3c742b6

Browse files
committed
feat(cluster): implement SWIM failure detector
Add the core SWIM/Lifeguard failure detection runtime to nodedb-cluster. The detector drives a tokio::select! probe loop that separates I/O from logic via a Transport trait, allowing deterministic in-process testing with InMemoryTransport and edge-drop/partition injection. - FailureDetector: main runtime task owning the probe loop, suspicion timer, and inflight-probe registry - ProbeRound: Lifeguard ping → ping-req indirect probe sequence with per-probe-id oneshot correlation - ProbeScheduler: random-permutation epoch scheduler (every peer probed once per epoch, per Lifeguard §4.3) - SuspicionTimer: timeout math per Lifeguard §3.1 (max(min, mult * log2(n) * probe_interval)) with drain_expired polling - Transport / InMemoryTransport / TransportFabric: Send+Sync async trait with mpsc-backed in-memory impl for unit tests - SwimError variants TransportClosed and ProbeInflightOverflow async-trait added to nodedb-cluster dependencies to support the Transport trait definition.
1 parent d4c88df commit 3c742b6

9 files changed

Lines changed: 1504 additions & 0 deletions

File tree

nodedb-cluster/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ thiserror = { workspace = true }
2222
tracing = { workspace = true }
2323
tokio = { workspace = true }
2424
rand = { workspace = true }
25+
async-trait = { workspace = true }
2526

2627
# Serialization (compact binary for RPCs — matches nexar wire format)
2728
rkyv = { workspace = true }
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! SWIM failure detector — the runtime that drives the probe loop.
2+
//!
3+
//! This module is the `!I/O` portion of the SWIM subsystem: it owns the
4+
//! probe scheduler, the suspicion timer, and the main `tokio::select!`
5+
//! loop. All actual networking is pushed behind the [`Transport`] trait
6+
//! so unit tests can run fully in-process against [`InMemoryTransport`]
7+
//! and the real UDP transport in E-ε can slot in without touching the
8+
//! detector logic.
9+
10+
pub mod probe_round;
11+
pub mod runner;
12+
pub mod scheduler;
13+
pub mod suspicion;
14+
pub mod transport;
15+
16+
pub use probe_round::{ProbeOutcome, ProbeRound};
17+
pub use runner::FailureDetector;
18+
pub use scheduler::ProbeScheduler;
19+
pub use suspicion::SuspicionTimer;
20+
pub use transport::{InMemoryTransport, Transport, TransportFabric};

0 commit comments

Comments
 (0)