Skip to main content

PersistentHost

Struct PersistentHost 

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

Long-lived host that drives compiled plans incrementally. Mutex- guarded HostInner is the single point of synchronization — the host is Send + Sync so the router can hold one Arc and call methods from any task.

Implementations§

Source§

impl PersistentHost

Source

pub fn new() -> Self

Construct an empty host.

Source

pub fn cached_view( &self, canonical: &str, subscriber: u64, ) -> Option<(Vec<Row>, Lsn)>

Try to attach subscriber to an already-registered plan under canonical. On hit, returns the current cached materialized view + the LSN that view reflects, and the subscriber is added to the plan’s fan-out list under the same lock. On miss, returns None so the caller can do the full snapshot pull and call Self::register_or_seed.

The atomic add-and-snapshot is the key to coherent live diffs for a late joiner: even if the cursor pump’s next apply_and_fanout races this call, exactly one of two things happens:

  • pump wins lock → applies, advances last_lsn, fans out deltas to current subscribers; our cached_view returns the post-apply view and adds us to the list, so we get the next delta.
  • cached_view wins lock → returns the pre-apply view and registers us; pump applies, advances last_lsn, fans out including us. Either way the new subscriber sees a consistent (Initial @ L, then live diffs > L) timeline.
Source

pub fn register_or_seed( &self, canonical: &str, plan: &CompiledPlan, inputs: HashMap<TableId, Vec<Row>>, snapshot_lsn: Lsn, subscriber: u64, ) -> Vec<Row>

Register plan under canonical with the supplied initial input snapshot and attach subscriber. Spawns a per-plan worker thread on first registration. Returns the materialized initial rows the caller should ship as Initial.

Callers should usually Self::cached_view first; if that returns None, run the snapshot pipeline and call this fn. If two threads race the snapshot pipeline for the same canonical, the loser’s seed work is discarded and the winning cached view is returned.

Source

pub fn subscribers(&self, canonical: &str) -> Option<Vec<u64>>

Returns the current subscribers attached to canonical, or None if no plan is registered. Used by the cursor pump to learn its fan-out targets without applying anything.

Source

pub fn push_table_diff( &self, canonical: &str, table_id: TableId, row: Row, diff: isize, lsn: Lsn, ) -> Vec<AggregateDelta>

Apply a single WAL diff. Convenience wrapper around Self::apply_and_fanout.

Source

pub fn apply_and_fanout( &self, canonical: &str, diffs: Vec<(TableId, Row, isize)>, lsn: Lsn, ) -> Option<(Vec<AggregateDelta>, Vec<u64>)>

Apply a batch of diffs at one LSN. Returns the resulting aggregate deltas and the current subscribers list — bundled so the cursor pump can fan out atomically without re-locking the host between apply and lookup.

Returns None if no plan is registered under canonical (the last subscriber released and the plan was torn down). Callers should treat that as their cue to exit.

Source

pub fn push_table_batch( &self, canonical: &str, diffs: Vec<(TableId, Row, isize)>, lsn: Lsn, ) -> Vec<AggregateDelta>

Legacy single-pump variant — applies and returns deltas only. Used by tests and the old per-subscription pump path.

Source

pub fn push_transaction( &self, canonical: &str, transaction: &WalTransaction, ) -> Vec<AggregateDelta>

Apply every row update from one committed WAL transaction.

Source

pub fn release(&self, canonical: &str, subscriber: u64) -> usize

Detach subscriber from canonical. Returns the count of subscribers that remain; once zero, the plan is torn down (the IncrementalDataflow is dropped, which sends Stop and joins the worker thread).

Trait Implementations§

Source§

impl Default for PersistentHost

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<'a, S, T> Semigroup<&'a S> for T
where T: Semigroup<S>,

Source§

fn plus_equals(&mut self, rhs: &&'a S)

The method of std::ops::AddAssign, for types that do not implement AddAssign.
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.