Skip to main content

ClusterKillSwitch

Struct ClusterKillSwitch 

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

Distributed emergency-halt latch. Cheap to clone via Arc.

Implementations§

Source§

impl ClusterKillSwitch

Source

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).

Source

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.

Source

pub fn replicator(&self) -> &Arc<Replicator>

Access the backing replicator (telemetry / testing).

Source

pub fn epoch(&self) -> u64

Current epoch (0 if unset).

Source

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.

Source

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.

Source

pub fn last_reason(&self) -> Option<HaltReason>

Reason recorded by the most recent local engage, if any.

Source

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.

Source

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.

Source

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 by local_timeout), then ack back to the originator.
  • HaltPdu::Ack — record a peer’s ack and wake any in-flight await_quiescence.
Source

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.

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, 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
Source§

impl<T> Extension for T
where T: Any + Send + Sync,