Skip to main content

AdaptiveRingSidecar

Struct AdaptiveRingSidecar 

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

Background scanner thread that drives shape morphs on an AdaptiveRing from a RingShapePolicy.

spawn starts the thread; shutdown stops it. The thread scans every scan_interval, builds a PolicyObservation, asks the policy, and calls AdaptiveRing::morph_to on Some(new_shape) responses.

Implementations§

Source§

impl AdaptiveRingSidecar

Source

pub fn spawn<P: RingShapePolicy>( ring: Arc<AdaptiveRing>, policy: P, scan_interval: Duration, ) -> Self

Spawn a sidecar thread that morphs ring according to policy decisions sampled every scan_interval.

Source

pub fn spawn_gated<P: RingShapePolicy>( ring: Arc<AdaptiveRing>, policy: P, scan_interval: Duration, gate_cfg: GateConfig, ) -> Self

As spawn with a confidence gate between the shape policy’s recommendation and the morph. Disabled (the default config) reproduces spawn exactly.

Source

pub fn spawn_with_qos<P: RingShapePolicy, O: OrderingPolicy>( ring: Arc<AdaptiveRing>, shape_policy: P, ordering_policy: O, qos: Arc<QosPolicy>, scan_interval: Duration, ) -> Self

Spawn a sidecar that consults BOTH axes every scan tick: the shape policy (peer counts + the QoS ordering declaration, via QosRingShapePolicy or any custom RingShapePolicy) and the ordering policy (declaration + observed inversion rate).

Per tick, on a stamped ring the sidecar additionally:

  • computes inversions/sec from the shared counter’s delta,
  • ticks the drainer-lease epoch so a dead merge drainer becomes preemptible after DRAINER_GRACE_EPOCHS scans,
  • applies the ordering policy’s decision via set_ordering_mode (counted in ordering_flips).

The shape axis is UNGATED by default: capacity-class morphs are cheap to reverse (the warm-backing path makes them microsecond-scale), so tracking load faithfully beats deliberating. The ordering AUTO-arm is GATED by default: the inversion-rate-driven Unordered -> MergeByStamp flip is one-way (merged pops read zero inversions, so there is no symmetric signal to walk it back), and a one-way decision taken on a single noisy scan is unrecoverable. The gate makes the auto-arm demand sustained inversions before it commits. Explicit caller declarations (GlobalFifo arm, declaration withdrawal) are NOT noise and fire immediately - only the auto-detected arm is deliberated.

spawn_with_qos_gated overrides both axes with one explicit config (disabled reproduces the fully-ungated behavior).

Source

pub fn spawn_with_qos_gated<P: RingShapePolicy, O: OrderingPolicy>( ring: Arc<AdaptiveRing>, shape_policy: P, ordering_policy: O, qos: Arc<QosPolicy>, scan_interval: Duration, gate_cfg: GateConfig, ) -> Self

As spawn_with_qos with confidence gates on BOTH axes set from one explicit config - a shape gate and an ordering-auto-arm gate (each accumulates its own conviction; a peer-count change shocks both). GateConfig::default() (disabled) reproduces the fully-ungated sidecar; an enabled config gates the shape morph AND the ordering auto-arm. Explicit ordering declarations always fire immediately regardless of config - the gate governs the auto-detected arm only.

Source

pub fn morphs_triggered(&self) -> u64

Number of successful morph_to calls the sidecar has issued since spawn.

Source

pub fn ordering_flips(&self) -> u64

Number of ordering-mode flips this sidecar has issued since spawn (always 0 for spawn).

Source

pub fn shutdown(self)

Stop the scanner thread and join it.

Trait Implementations§

Source§

impl Drop for AdaptiveRingSidecar

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

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