pub struct Cluster<N> { /* private fields */ }
Expand description
Utility to ease the implementation of changes in cluster membership, i.e. joining and parting of nodes, and concurrency.
This utility is most useful to implementors of the State
trait. Whenever a log entry is applied it should also
be applied to this Cluster
. If done consistently,
concurrency_at_offset_one
and
nodes_at
can be used to trivially implement the
methods concurrency
and
cluster_at
.
Membership Changes
No limits are placed on membership changes. Practically speaking, however, it is wise not to make significant changes quickly. Nodes should not become voting members of a cluster until they can be certain they won’t break an earlier commitment.
Concurrency Increases
The implementation is “optimal” in that it takes advantage of concurrency increases the moment they become known.
Round | r | r + 1 | r + 2 | … |
---|---|---|---|---|
Log Entry | c ≔ 5 | |||
Target Concurrency | 2 | 5 | 5 | … |
Effective Concurrency | 2 | 5 | 5 | … |
Concurrency Decreases
When concurrency is decreased, it cannot be assumed that everyone knows of
this reduction until the the previous concurrency window is exhausted.
Consider that the concurrency level is 5
in round r
and is then reduced
by a log entry in round r + 1
. Any node that does not see that log entry
in time may think the concurrency level is unchanged, at least until it
exhausts the concurrency of 5
in round r + 5
. Any further append to the
log is only allowed while taking the reduction into account. That means that
in effect the concurrency level slowly reduces from 5
to 2
, as if the
5
throws a shadow along the axis of concurrency.
Round | r | r + 1 | r + 2 | r + 3 | r + 4 | r + 5 | … |
---|---|---|---|---|---|---|---|
Log Entry | c ≔ 2 | ||||||
Target Concurrency | 5 | 2 | 2 | 2 | 2 | 2 | … |
Effective Concurrency | 5 | 5 | 4 | 3 | 2 | 2 | … |
Implementations
sourceimpl<N, I> Cluster<N> where
N: NodeInfo<Id = I> + Clone,
I: Identifier + Ord,
impl<N, I> Cluster<N> where
N: NodeInfo<Id = I> + Clone,
I: Identifier + Ord,
sourcepub fn new(nodes: Vec<N>, concurrency: NonZeroUsize) -> Self
pub fn new(nodes: Vec<N>, concurrency: NonZeroUsize) -> Self
Returns a new cluster with the given initial state.
sourcepub fn apply<E: ClusterLogEntry<N>>(&mut self, log_entry: &E)
pub fn apply<E: ClusterLogEntry<N>>(&mut self, log_entry: &E)
Applies the given log entry, making the appropiate updates.
sourcepub fn concurrency_at_offset_one(&self) -> NonZeroUsize
pub fn concurrency_at_offset_one(&self) -> NonZeroUsize
Returns the concurrency at offset one.
sourcepub fn nodes_at_offset_one(&self) -> Vec<N>
pub fn nodes_at_offset_one(&self) -> Vec<N>
Equivalent to c.nodes_at(NonZeroUsize::new(1).unwrap()).unwrap()
.
sourcepub fn nodes_at(&self, round_offset: NonZeroUsize) -> Option<Vec<N>>
pub fn nodes_at(&self, round_offset: NonZeroUsize) -> Option<Vec<N>>
Returns effective set of nodes of the cluster for the given round number
or None
when the level of concurrency does not allow the node set to
be determined yet.
Trait Implementations
sourceimpl<'de, N> Deserialize<'de> for Cluster<N> where
N: Deserialize<'de>,
impl<'de, N> Deserialize<'de> for Cluster<N> where
N: Deserialize<'de>,
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations
impl<N> RefUnwindSafe for Cluster<N> where
N: RefUnwindSafe,
impl<N> Send for Cluster<N> where
N: Send,
impl<N> Sync for Cluster<N> where
N: Sync,
impl<N> Unpin for Cluster<N> where
N: Unpin,
impl<N> UnwindSafe for Cluster<N> where
N: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more