Skip to main content

InMemoryGroup

Struct InMemoryGroup 

Source
pub struct InMemoryGroup { /* private fields */ }
Expand description

An n-node fully-connected in-memory replication mesh.

InMemoryGroup owns one InMemoryEndpoint per ordered (from, to) peer pair (with from != to). The endpoint at (from, to) is from’s view of its socket to to; sending on that endpoint is observed by the endpoint at (to, from).

Higher layers typically consume the group by handing each node the row of channels [group.channel(my_id, peer)] for peer in 0..n.

§Crash and recovery

InMemoryGroup::simulate_crash closes every channel touching a node, modelling a hard crash or partition. After a crash, InMemoryGroup::reconnect rewires that node’s row of channels (paired against the other live nodes) to model a node restart or healed partition. A crashed node may be reconnected at most once per crash; the implementation tolerates repeated calls.

Implementations§

Source§

impl InMemoryGroup

Source

pub fn size(&self) -> usize

Number of nodes in the mesh.

Source

pub fn channel(&self, from: usize, to: usize) -> Arc<dyn Channel>

Return a cheap Arc<dyn Channel> handle to the directed channel from from to to.

§Panics

Panics if from or to is out of range, if from == to, or if the channel has been removed by Self::simulate_crash without a subsequent Self::reconnect.

Source

pub fn try_channel(&self, from: usize, to: usize) -> Option<Arc<dyn Channel>>

Try to acquire the directed channel from from to to, returning None if the channel has been crashed.

§Panics

Panics on out-of-range indices or from == to.

Source

pub fn simulate_crash(&self, node: usize)

Simulate a hard crash of node: every channel originating from or terminating at node is closed and dropped from the mesh. Subsequent send / receive on any handle that was previously cloned out of those channels returns crate::error::RepError::ChannelClosed, matching a real socket disconnect.

Idempotent: calling simulate_crash on an already-crashed node is a no-op.

§Panics

Panics if node is out of range.

Source

pub fn reconnect(&self, node: usize)

Rewire node’s row of channels against every peer that is still live (i.e., still has a channel slot to node). Models a node restart or a healed partition.

Channels whose remote end is itself currently crashed are left disconnected; the caller should reconnect them in a separate pass once the remote node has come back.

§Panics

Panics if node is out of range.

Source

pub fn is_node_live(&self, node: usize) -> bool

Return true iff every directed channel touching node is currently open.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V