pub struct ClusterKillSwitch { /* private fields */ }Expand description
Distributed emergency-halt latch. Cheap to clone via Arc.
Implementations§
Source§impl ClusterKillSwitch
impl ClusterKillSwitch
Sourcepub fn new(
replicator: Arc<Replicator>,
base_key: impl Into<String>,
node: impl Into<String>,
) -> Arc<Self>
pub fn new( replicator: Arc<Replicator>, base_key: impl Into<String>, node: impl Into<String>, ) -> Arc<Self>
Create a switch over replicator, gating on the well-known
base_key. node is this node’s stable id (used for LWW
register tie-breaking on the epoch counter).
Sourcepub fn with_transport(
replicator: Arc<Replicator>,
base_key: impl Into<String>,
node: impl Into<String>,
transport: Arc<dyn HaltTransport>,
) -> Arc<Self>
pub fn with_transport( replicator: Arc<Replicator>, base_key: impl Into<String>, node: impl Into<String>, transport: Arc<dyn HaltTransport>, ) -> Arc<Self>
Like new but attaches a HaltTransport so
await_quiescence also fans the halt out
to remote peers and collects their acks.
Sourcepub fn replicator(&self) -> &Arc<Replicator>
pub fn replicator(&self) -> &Arc<Replicator>
Access the backing replicator (telemetry / testing).
Sourcepub fn engage(&self, reason: HaltReason) -> HaltToken
pub fn engage(&self, reason: HaltReason) -> HaltToken
Engage the latch for the current epoch and record reason.
Idempotent at the CRDT level (OR-merge); calling twice is safe.
Sourcepub fn is_engaged(&self) -> bool
pub fn is_engaged(&self) -> bool
Read the merged latch state for the current epoch. Survives
merge/rebalance because the backing Flag only OR-merges.
Sourcepub fn last_reason(&self) -> Option<HaltReason>
pub fn last_reason(&self) -> Option<HaltReason>
Reason recorded by the most recent local engage, if any.
Sourcepub fn register_guarded(&self, party: Box<dyn HaltGuarded>) -> AckHandle
pub fn register_guarded(&self, party: Box<dyn HaltGuarded>) -> AckHandle
Register a guarded party. Returns an AckHandle the party
keeps; when its on_halt runs (during await_quiescence) it
signals quiescence by calling AckHandle::ack.
Sourcepub async fn await_quiescence(&self, timeout: Duration) -> QuiescenceReport
pub async fn await_quiescence(&self, timeout: Duration) -> QuiescenceReport
Bring the system to a safe stop and report how many parties
acknowledged within timeout.
Always quiesces this node’s local HaltGuarded parties. When a
HaltTransport is attached it also broadcasts a
HaltPdu::Halt to every peer and waits for a HaltPdu::Ack
from each, so the returned QuiescenceReport reflects the whole
cluster. timeout bounds the combined wait.
Sourcepub async fn apply_pdu(&self, pdu: HaltPdu, local_timeout: Duration)
pub async fn apply_pdu(&self, pdu: HaltPdu, local_timeout: Duration)
Apply an inbound HaltPdu delivered by a HaltTransport.
HaltPdu::Halt— engage this node’s latch for the named epoch, quiesce its local guarded parties (bounded bylocal_timeout), then ack back to the originator.HaltPdu::Ack— record a peer’s ack and wake any in-flightawait_quiescence.
Sourcepub fn reset(&self, authz: ResetAuthorization) -> Result<u64, ResetError>
pub fn reset(&self, authz: ResetAuthorization) -> Result<u64, ResetError>
Reset the switch by advancing to a fresh epoch (the old epoch’s
latched flag is left as an audit record). Requires a valid
two-person ResetAuthorization.
See the module docs for why this advances an epoch instead of
flipping the flag: a Flag cannot un-latch.