Skip to main content

ProjectionRouter

Struct ProjectionRouter 

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

Event-stream dispatcher. Matches incoming events to registered projections by TypeCode, enforces dedup + gap detection via Projection::last_applied, and propagates observer state transitions.

Implementations§

Source§

impl ProjectionRouter

Source

pub fn new() -> Self

Build a router in the Passive state — promote to Active before committing writes.

Source

pub fn register(&mut self, projection: Box<dyn Projection>)

Register a projection.

Source

pub fn state(&self) -> ObserverState

Current observer state.

Source

pub fn promote_to_active(&mut self) -> Result<(), ProjectionError>

Transition to Active — fails if currently Draining.

Source

pub fn evaluate_auto_promote( &self, manifest: &ManifestSnapshot, primary_down_duration: Duration, health: &MultiChannelHealth, threshold_ready: bool, ) -> Option<PromotionDecision>

Evaluate the shell’s kms_auto_promote policy against three inputs: the elapsed outage, the multi-channel KMS health quorum, and the threshold-HSM share readiness.

Policy values:

kms_auto_promoteDecision matrix
"manual"Always Some(Wait) — operator drives the promotion manually.
"after_60min"Some(Promote) iff primary_down_duration >= 1h and the KMS health quorum has at least HF2_HEALTH_QUORUM_MIN channels healthy; otherwise Some(Wait).
"threshold_hsm"Some(Promote) iff threshold_ready (t-of-n shares collected); otherwise Some(Wait).
otherNone — unrecognised policy string, operator intervention required.

Returning None is conservative by design: callers treat unknown policies as “do not auto-promote” and fall back to manual operator action.

Source

pub fn demote_to_passive(&mut self) -> Result<(), ProjectionError>

Transition to Passive. Used when ceding primary to a peer.

Source

pub fn begin_draining(&mut self) -> Result<(), ProjectionError>

Transition to Draining. Terminal — no further state changes.

Source

pub fn dispatch( &mut self, event: &EventRecord, ctx: &ProjectionContext<'_>, ) -> Result<usize, ProjectionError>

Dispatch an event to every matching projection. Returns Ok(n) where n is the number of projections that applied the event.

Only the Active state may dispatch — Passive and Draining reject with ProjectionError::NotActive. The Passive rejection is the production guardrail for active-passive HA: a secondary observer that mistakenly accepts writes would create split-brain rows in the PG-backed store. The dylint arkhe-trait-default-check CI gate ensures the contract is honoured by every L2 deployment.

Trait Implementations§

Source§

impl Default for ProjectionRouter

Source§

fn default() -> Self

Returns the “default value” for a type. 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> Same for T

Source§

type Output = T

Should always be Self
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.