Trait mz_persist::location::Consensus

source ·
pub trait Consensus: Debug {
    // Required methods
    fn list_keys(&self) -> ResultStream<'_, String>;
    fn head<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str
    ) -> Pin<Box<dyn Future<Output = Result<Option<VersionedData>, ExternalError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn compare_and_set<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        expected: Option<SeqNo>,
        new: VersionedData
    ) -> Pin<Box<dyn Future<Output = Result<CaSResult, ExternalError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn scan<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        from: SeqNo,
        limit: usize
    ) -> Pin<Box<dyn Future<Output = Result<Vec<VersionedData>, ExternalError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn truncate<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        seqno: SeqNo
    ) -> Pin<Box<dyn Future<Output = Result<usize, ExternalError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

An abstraction for VersionedData held in a location in persistent storage where the data are conditionally updated by version.

Users are expected to use this API with consistently increasing sequence numbers to allow multiple processes across multiple machines to agree to a total order of the evolution of the data. To make roundtripping through various forms of durable storage easier, sequence numbers used with Consensus need to be restricted to the range [0, i64::MAX].

Required Methods§

source

fn list_keys(&self) -> ResultStream<'_, String>

Returns all the keys ever created in the consensus store.

source

fn head<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str ) -> Pin<Box<dyn Future<Output = Result<Option<VersionedData>, ExternalError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Returns a recent version of data, and the corresponding sequence number, if one exists at this location.

source

fn compare_and_set<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, expected: Option<SeqNo>, new: VersionedData ) -> Pin<Box<dyn Future<Output = Result<CaSResult, ExternalError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Update the VersionedData stored at this location to new, iff the current sequence number is exactly expected and new’s sequence number > the current sequence number.

It is invalid to call this function with a new and expected such that new’s sequence number is <= expected. It is invalid to call this function with a sequence number outside of the range [0, i64::MAX].

This data is initialized to None, and the first call to compare_and_set needs to happen with None as the expected value to set the state.

source

fn scan<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, from: SeqNo, limit: usize ) -> Pin<Box<dyn Future<Output = Result<Vec<VersionedData>, ExternalError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Return limit versions of data stored for this key at sequence numbers >= from, in ascending order of sequence number.

Returns an empty vec if from is greater than the current sequence number or if there is no data at this key.

source

fn truncate<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, seqno: SeqNo ) -> Pin<Box<dyn Future<Output = Result<usize, ExternalError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Deletes all historical versions of the data stored at key that are < seqno, iff seqno <= the current sequence number.

Returns the number of versions deleted on success. Returns an error if seqno is greater than the current sequence number, or if there is no data at this key.

Implementors§