[][src]Trait paxakos::State

pub trait State: 'static + Clone + Debug + Send + Sized + Sync {
    type Reader: Read;
    type LogEntry: LogEntry;
    type Context: Debug + Send;
    type Outcome: 'static + Clone + Debug + Send + Sync + Unpin;
    type Event: 'static + Send + Debug;
    type Node: NodeInfo;
#[must_use]    fn from_reader<'async_trait, R: AsyncRead + Unpin>(
        read: R
    ) -> Pin<Box<dyn Future<Output = Result<Self, BoxError>> + 'async_trait>>
    where
        R: 'async_trait,
        Self: 'async_trait
;
fn size(&self) -> usize;
fn to_reader(&self) -> Self::Reader;
fn apply(
        &mut self,
        log_entry: &Self::LogEntry,
        context: &mut Self::Context
    ) -> (Self::Outcome, Self::Event);
fn cluster_at(&self, round_offset: NonZeroUsize) -> Vec<Self::Node>; fn apply_unobserved(
        &mut self,
        log_entry: &Self::LogEntry,
        context: &mut Self::Context
    ) -> Self::Event { ... }
fn contains(
        &self,
        _log_entry_id: <Self::LogEntry as LogEntry>::Id
    ) -> Result<bool, ()> { ... }
fn concurrency(&self) -> NonZeroUsize { ... } }

Distributed state to which log entries are applied.

Associated Types

type Reader: Read

type LogEntry: LogEntry

type Context: Debug + Send

An execution context.

The execution context commonly provides access to a working directory or other state that is node and instance specific.

type Outcome: 'static + Clone + Debug + Send + Sync + Unpin

Result of applying a log entry to the state.

This result is what those actively appending to the log receive.

type Event: 'static + Send + Debug

Result of applying a log entry to the state.

This result is emitted as an Apply event event.

type Node: NodeInfo

Loading content...

Required methods

#[must_use]fn from_reader<'async_trait, R: AsyncRead + Unpin>(
    read: R
) -> Pin<Box<dyn Future<Output = Result<Self, BoxError>> + 'async_trait>> where
    R: 'async_trait,
    Self: 'async_trait, 

Deserializes state that was previously serialized using to_reader().

While implementations need not detect arbitrary data corruption, they must not panic.

fn size(&self) -> usize

Number of bytes the result of to_reader() will emit.

fn to_reader(&self) -> Self::Reader

Serializes the state to enable snapshots.

State::from_reader(s.to_reader()) must yield an equivalent state.

fn apply(
    &mut self,
    log_entry: &Self::LogEntry,
    context: &mut Self::Context
) -> (Self::Outcome, Self::Event)

Applies the given log entry to this state object.

Implementations do not have to account for out-of-order application. Log entries are applied in a consistent order accross the cluster.

Note: The distributed log may contain duplicates of the same event, i.e. entries e1 and e2 may be appended to the log for rounds r1 and r2 such that e1.id() == e2.id() and r1 != r2. Implementations that choose to ignore the application of the second entry must take care to do so in a fashion that is consistent across the cluster.

fn cluster_at(&self, round_offset: NonZeroUsize) -> Vec<Self::Node>

Returns the set of nodes that make up the cluster at the given round offset.

The round offset is guaranteed to be less than or equal to the current level of concurrency. As such there must always be a known set of nodes that make up the cluster for the given round.

The order of the returned set must be determisistic, meaning it must be consistent across the entire cluster.

Loading content...

Provided methods

fn apply_unobserved(
    &mut self,
    log_entry: &Self::LogEntry,
    context: &mut Self::Context
) -> Self::Event

Applies the given log entry to this state object.

This method may be implemented as an optimization. It is called instead of apply when there are no observers for the result object.

Careful: Implementations must be equivalent to the default implementation in their effects.

fn contains(
    &self,
    _log_entry_id: <Self::LogEntry as LogEntry>::Id
) -> Result<bool, ()>

Returns whether an entry with log_entry_id was applied to this state.

This method is called before a node attempts to append an entry to the log. When false is returned the node proceeds in its attempt. Otherwise the attempt is abandoned with an appropriate error.

Careful: Please note that this is strictly an optimization. There is no way to prevent an event from being applied multiple times unless the concurrency level is reduced to one.

fn concurrency(&self) -> NonZeroUsize

Returns the current level of concurrency, defaults to one.

Loading content...

Implementors

Loading content...