Skip to main content

ChangeStream

Trait ChangeStream 

Source
pub trait ChangeStream:
    Debug
    + Send
    + Sync
    + 'static {
    // Required method
    fn join<'life0, 'async_trait>(
        &'life0 self,
        timeout: Duration,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn begin_write<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 ObjectId,
        expires_at: Option<Timestamp>,
    ) -> Pin<Box<dyn Future<Output = Result<(), ChangeStreamError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn commit_write<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 ObjectId,
        size: u64,
        expires_at: Option<Timestamp>,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn begin_update<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 ObjectId,
        expires_at: Option<Timestamp>,
    ) -> Pin<Box<dyn Future<Output = Result<(), ChangeStreamError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn commit_update<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 ObjectId,
        expires_at: Option<Timestamp>,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn commit_delete<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 ObjectId,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Publishes the changes a single backend makes to the objects it stores.

Backends call begin_* before a storage operation that creates data or extends its lifetime, and commit_* after a storage operation succeeds. A failed begin_* fails the request before storage is touched. A begin_* is not always followed by a commit_* (e.g. when the storage operation fails), so consumers that must never underestimate what is stored should treat begin_* as an upper bound.

All methods but join default to doing nothing. Backends await them on the request path, so they add to request latency.

Consider spawning and independent task or using a queue in your implementation of the methods if you only need best-effort delivery.

See module docs.

Required Methods§

Source

fn join<'life0, 'async_trait>( &'life0 self, timeout: Duration, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Blocks until reported records have been delivered, or timeout elapses.

Call this during shutdown to drain the change stream queue. Waits for reported records to be delivered, or until timeout elapses.

Awaited from Backend::join so records reported just before shutdown are not lost.

Provided Methods§

Source

fn begin_write<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ObjectId, expires_at: Option<Timestamp>, ) -> Pin<Box<dyn Future<Output = Result<(), ChangeStreamError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Announces that id is about to be written. Used for new writes and overwrites.

Source

fn commit_write<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ObjectId, size: u64, expires_at: Option<Timestamp>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Reports that id now occupies size bytes. Used for new writes and overwrites.

Source

fn begin_update<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ObjectId, expires_at: Option<Timestamp>, ) -> Pin<Box<dyn Future<Output = Result<(), ChangeStreamError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Announces that id’s expiration is about to move out to expires_at.

Source

fn commit_update<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ObjectId, expires_at: Option<Timestamp>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Reports that id’s expiration moved, with its stored size unchanged.

Source

fn commit_delete<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ObjectId, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Reports that id was deleted explicitly. Does not account for automatic GC.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl ChangeStream for NoopStream

Source§

impl<P> ChangeStream for CostTrackerStream<P>
where P: Producer + Clone + Send + Sync + 'static, P::Error: Into<BoxError> + Send + 'static,