Skip to main content

Processor

Struct Processor 

Source
pub struct Processor<R: Reducer, D: Db, T, E: EventHandler<R::Event>> { /* private fields */ }
Expand description

Drives a Reducer over a Db: applies local writes (exec) and ingests remote log entries, advancing the HLC and per-peer cursors and emitting change events through its EventHandler. This is the concrete engine behind the Store/SqlStore surface (open one with open); it also implements the sync traits.

Implementations§

Source§

impl<R: Reducer, D: Db, T: LogTracker<R::Op>, E: EventHandler<R::Event>> Processor<R, D, T, E>

Source

pub async fn open( reducer: R, db: D, prefix: &str, self_id: Uuid, ) -> Result<Self, ProcessorError<R::Error>>

Open a processor against db: set up HLC storage and the tracker (both namespaced by prefix), seed the clock and cursor view from persisted state, and take ownership of reducer.

Source

pub async fn exec( &self, server_user_id: Option<Uuid>, op: R::Op, ) -> Result<(), ProcessorError<R::Error>>

Apply a local write: mint a fresh entry under self_id and ingest it, advancing self’s cursor.

Source

pub fn event_handler(&self) -> &E

The handler this processor emits into — subscribe off it.

Trait Implementations§

Source§

impl<R: Reducer, D: Db, T: Send + Sync, E: EventHandler<R::Event> + Send + Sync> HasCursors for Processor<R, D, T, E>
where E::Publish: Send + Sync,

Source§

fn cursors<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<PeerCursors, SyncError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Snapshot of the current cursor vector.
Source§

fn watch_cursors(&self) -> CursorStream

Live cursor progress: a first Snapshot, then Advanced deltas.
Source§

impl<R: Reducer, D: Db, T: LogTracker<R::Op>, E: EventHandler<R::Event> + Send + Sync> LogProcessor<<R as Reducer>::Op> for Processor<R, D, T, E>
where R::Error: Error + Send + Sync + 'static, E::Publish: Send + Sync,

Source§

fn apply<'life0, 'async_trait>( &'life0 self, peer: Uuid, index: u64, entry: DecodedEntry<R::Op>, ) -> Pin<Box<dyn Future<Output = Result<Applied, SyncError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Apply one entry at (peer, index), advancing the cursor for peer to index + 1. Idempotent (see the trait docs).
Source§

impl<R: Reducer, D: Db, T: HistoryTracker<R::Op>, E: EventHandler<R::Event> + Send + Sync> LogSource<<R as Reducer>::Op> for Processor<R, D, T, E>
where R::Error: Error + Send + Sync + 'static, E::Publish: Send + Sync,

Source§

fn read_since<'life0, 'async_trait>( &'life0 self, peer: Uuid, from: u64, ) -> Pin<Box<dyn Future<Output = Result<Vec<(u64, DecodedEntry<R::Op>)>, SyncError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

A bounded batch of peer’s entries at or after from, ascending (expunged markers included). Empty means drained at from; the caller loops with an advancing from until then.
Source§

impl<R: Reducer, D: Db, T: LogTracker<R::Op>> SqlStore<<R as Reducer>::Op, <R as Reducer>::Event> for Processor<R, D, T, EventBus<R::Event>>
where R::Event: RoutableEvent, R::Error: Error + Send + Sync + 'static, <R::Event as RoutableEvent>::Target: Send + Sync,

Source§

fn query<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, sql: &'life1 str, params: &'life2 [DbValue], ) -> Pin<Box<dyn Future<Output = Result<Vec<DbRow>, DbError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Run a read-only query against the backend.
Source§

fn dialect(&self) -> SqlDialect

The backend’s SQL dialect — lets a caller build dialect-correct SQL (placeholder style, quoting) to hand back to query.
Source§

impl<R: Reducer, D: Db, T: LogTracker<R::Op>> Store<<R as Reducer>::Op, ProcessorError<Box<dyn Error + Send + Sync>>, <R as Reducer>::Event> for Processor<R, D, T, EventBus<R::Event>>
where R::Event: RoutableEvent, R::Error: Error + Send + Sync + 'static, <R::Event as RoutableEvent>::Target: Send + Sync,

Source§

fn exec<'life0, 'async_trait>( &'life0 self, server_user_id: Option<Uuid>, op: R::Op, ) -> Pin<Box<dyn Future<Output = Result<(), ProcessorError<BoxError>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Apply a local write, minting a fresh log entry for it.
Source§

fn watch( &self, target: <R::Event as RoutableEvent>::Target, ) -> Subscription<R::Event>

Subscribe to events routed to target; dropping the subscription unsubscribes.

Auto Trait Implementations§

§

impl<R, D, T, E> !Freeze for Processor<R, D, T, E>

§

impl<R, D, T, E> !RefUnwindSafe for Processor<R, D, T, E>

§

impl<R, D, T, E> Send for Processor<R, D, T, E>
where T: Send, <E as EventHandler<<R as Reducer>::Event>>::Publish: Send, E: Send,

§

impl<R, D, T, E> Sync for Processor<R, D, T, E>
where T: Sync, <E as EventHandler<<R as Reducer>::Event>>::Publish: Sync, E: Sync,

§

impl<R, D, T, E> Unpin for Processor<R, D, T, E>
where D: Unpin, T: Unpin, <E as EventHandler<<R as Reducer>::Event>>::Publish: Unpin, E: Unpin, R: Unpin,

§

impl<R, D, T, E> UnsafeUnpin for Processor<R, D, T, E>

§

impl<R, D, T, E> UnwindSafe for Processor<R, D, T, E>

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<E, T> Replica<E> for T
where T: LogProcessor<E> + LogSource<E>,

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.