pub trait State: 'static + Debug + Send + Sized + Sync {
type Frozen: Frozen<Self> + Send + Sync + Debug;
type LogEntry: LogEntry;
type Context: Debug + Send;
type Outcome: 'static + Clone + Debug + Send + Sync + Unpin;
type Effect: 'static + Send + Debug;
type Node: NodeInfo;
fn apply(
&mut self,
log_entry: &Self::LogEntry,
context: &mut Self::Context
) -> (Self::Outcome, Self::Effect);
fn cluster_at(&self, round_offset: NonZeroUsize) -> Vec<Self::Node>;
fn freeze(&self) -> Self::Frozen;
fn apply_unobserved(
&mut self,
log_entry: &Self::LogEntry,
context: &mut Self::Context
) -> Self::Effect { ... }
fn concurrency(this: Option<&Self>) -> Option<NonZeroUsize> { ... }
}
Expand description
Distributed state to which log entries are applied.
Required Associated Types
An execution context.
The execution context commonly provides access to a working directory or other state that is node and instance specific.
Result of applying a log entry to the state.
This result is what those actively appending to the log receive.
Result of applying a log entry to the state.
This result is emitted as an Apply
event event.
Required Methods
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>
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.
Provided Methods
fn apply_unobserved(
&mut self,
log_entry: &Self::LogEntry,
context: &mut Self::Context
) -> Self::Effect
fn apply_unobserved(
&mut self,
log_entry: &Self::LogEntry,
context: &mut Self::Context
) -> Self::Effect
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 concurrency(this: Option<&Self>) -> Option<NonZeroUsize>
fn concurrency(this: Option<&Self>) -> Option<NonZeroUsize>
Returns the current level of concurrency.
Implementations must return Some
when the argument is Some
.
This function’s contract admits two kinds of implementation. The first
kind returns a constant value independent of the argument. The second
kind returns None
when the argument is None
and Some(value)
otherwise. The latter kind allows for the level of concurrency to change
dynamically yet remain consistent across the cluster.
The default implementation always returns Some(1)
.