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
impl PersistentHost
Sourcepub fn cached_view(
&self,
canonical: &str,
subscriber: u64,
) -> Option<(Vec<Row>, Lsn)>
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; ourcached_viewreturns 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.
Sourcepub fn register_or_seed(
&self,
canonical: &str,
plan: &CompiledPlan,
inputs: HashMap<TableId, Vec<Row>>,
snapshot_lsn: Lsn,
subscriber: u64,
) -> Vec<Row> ⓘ
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.
Sourcepub fn subscribers(&self, canonical: &str) -> Option<Vec<u64>>
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.
Sourcepub fn push_table_diff(
&self,
canonical: &str,
table_id: TableId,
row: Row,
diff: isize,
lsn: Lsn,
) -> Vec<AggregateDelta>
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.
Sourcepub fn apply_and_fanout(
&self,
canonical: &str,
diffs: Vec<(TableId, Row, isize)>,
lsn: Lsn,
) -> Option<(Vec<AggregateDelta>, Vec<u64>)>
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.
Sourcepub fn push_table_batch(
&self,
canonical: &str,
diffs: Vec<(TableId, Row, isize)>,
lsn: Lsn,
) -> Vec<AggregateDelta>
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.
Sourcepub fn push_transaction(
&self,
canonical: &str,
transaction: &WalTransaction,
) -> Vec<AggregateDelta>
pub fn push_transaction( &self, canonical: &str, transaction: &WalTransaction, ) -> Vec<AggregateDelta>
Apply every row update from one committed WAL transaction.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PersistentHost
impl RefUnwindSafe for PersistentHost
impl Send for PersistentHost
impl Sync for PersistentHost
impl Unpin for PersistentHost
impl UnsafeUnpin for PersistentHost
impl UnwindSafe for PersistentHost
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<'a, S, T> Semigroup<&'a S> for Twhere
T: Semigroup<S>,
impl<'a, S, T> Semigroup<&'a S> for Twhere
T: Semigroup<S>,
Source§fn plus_equals(&mut self, rhs: &&'a S)
fn plus_equals(&mut self, rhs: &&'a S)
std::ops::AddAssign, for types that do not implement AddAssign.