Memberlist

Struct Memberlist 

Source
pub struct Memberlist<T, D = VoidDelegate<<T as Transport>::Id, <<T as Transport>::Resolver as AddressResolver>::ResolvedAddress>>
where D: Delegate<Id = <T as Transport>::Id, Address = <T as Transport>::ResolvedAddress>, T: Transport,
{ /* private fields */ }
Expand description

A cluster membership and member failure detection using a gossip based protocol.

The use cases for such a library are far-reaching: all distributed systems require membership, and memberlist is a re-usable solution to managing cluster membership and node failure detection.

memberlist is eventually consistent but converges quickly on average. The speed at which it converges can be heavily tuned via various knobs on the protocol. Node failures are detected and network partitions are partially tolerated by attempting to communicate to potentially dead nodes through multiple routes.

Implementations§

Source§

impl<T, D> Memberlist<T, D>
where D: Delegate<Id = <T as Transport>::Id, Address = <T as Transport>::ResolvedAddress>, T: Transport,

Source

pub fn local_id(&self) -> &<T as Transport>::Id

Available on crate feature tokio only.

Returns the local node ID.

Source

pub fn local_address( &self, ) -> &<<T as Transport>::Resolver as AddressResolver>::Address

Available on crate feature tokio only.

Returns the local node address

Source

pub fn advertise_node( &self, ) -> Node<<T as Transport>::Id, <T as Transport>::ResolvedAddress>

Available on crate feature tokio only.

Returns a Node with the local id and the advertise address of local node.

Source

pub fn advertise_address(&self) -> &<T as Transport>::ResolvedAddress

Available on crate feature tokio only.

Returns the advertise address of local node.

Source

pub fn keyring(&self) -> Option<&Keyring>

Available on crate feature tokio only.

Returns the keyring (only used for encryption) of the node

Source

pub fn encryption_enabled(&self) -> bool

Available on crate feature tokio only.

Returns true if the node enables encryption.

Source

pub fn delegate(&self) -> Option<&D>

Available on crate feature tokio only.

Returns the delegate, if any.

Source

pub async fn local_state( &self, ) -> Option<Arc<NodeState<<T as Transport>::Id, <T as Transport>::ResolvedAddress>>>

Available on crate feature tokio only.

Returns the local node instance state.

Source

pub async fn by_id( &self, id: &<T as Transport>::Id, ) -> Option<Arc<NodeState<<T as Transport>::Id, <T as Transport>::ResolvedAddress>>>

Available on crate feature tokio only.

Returns the node state of the given id. (if any).

Source

pub async fn members( &self, ) -> SmallVec<Arc<NodeState<<T as Transport>::Id, <T as Transport>::ResolvedAddress>>>

Available on crate feature tokio only.

Returns a list of all known nodes.

Source

pub async fn num_members(&self) -> usize

Available on crate feature tokio only.

Returns number of members

Source

pub async fn online_members( &self, ) -> SmallVec<Arc<NodeState<<T as Transport>::Id, <T as Transport>::ResolvedAddress>>>

Available on crate feature tokio only.

Returns a list of all known nodes that are online.

Source

pub async fn num_online_members(&self) -> usize

Available on crate feature tokio only.

Returns the number of online members.

Source

pub async fn members_by( &self, f: impl FnMut(&NodeState<<T as Transport>::Id, <T as Transport>::ResolvedAddress>) -> bool, ) -> SmallVec<Arc<NodeState<<T as Transport>::Id, <T as Transport>::ResolvedAddress>>>

Available on crate feature tokio only.

Returns a list of all known nodes that match the given predicate.

Source

pub async fn num_members_by( &self, f: impl FnMut(&NodeState<<T as Transport>::Id, <T as Transport>::ResolvedAddress>) -> bool, ) -> usize

Available on crate feature tokio only.

Returns the number of members match the given predicate.

Source

pub async fn members_map_by<O>( &self, f: impl FnMut(&NodeState<<T as Transport>::Id, <T as Transport>::ResolvedAddress>) -> Option<O>, ) -> SmallVec<O>

Available on crate feature tokio only.

Returns a list of map result on all known members that match the given predicate.

Source§

impl<T> Memberlist<T>
where T: Transport,

Source

pub async fn new( transport_options: <T as Transport>::Options, opts: Options, ) -> Result<Memberlist<T>, Error<T, VoidDelegate<<T as Transport>::Id, <T as Transport>::ResolvedAddress>>>

Available on crate feature tokio only.

Create a new memberlist with the given transport and options.

Source§

impl<T, D> Memberlist<T, D>
where D: Delegate<Id = <T as Transport>::Id, Address = <T as Transport>::ResolvedAddress>, T: Transport,

Source

pub async fn with_delegate( delegate: D, transport_options: <T as Transport>::Options, opts: Options, ) -> Result<Memberlist<T, D>, Error<T, D>>

Available on crate feature tokio only.

Create a new memberlist with the given transport, delegate and options.

Source

pub async fn leave(&self, timeout: Duration) -> Result<bool, Error<T, D>>

Available on crate feature tokio only.

Leave will broadcast a leave message but will not shutdown the background listeners, meaning the node will continue participating in gossip and state updates.

This will block until the leave message is successfully broadcasted to a member of the cluster, if any exist or until a specified timeout is reached.

This method is safe to call multiple times, but must not be called after the cluster is already shut down.

Returns true if the node has successfully left the cluster by this call.

Source

pub async fn join( &self, node: Node<<T as Transport>::Id, MaybeResolvedAddress<<T as Transport>::Address, <T as Transport>::ResolvedAddress>>, ) -> Result<Node<<T as Transport>::Id, <T as Transport>::ResolvedAddress>, Error<T, D>>

Available on crate feature tokio only.

Join directly by contacting the given node id, Returns the node if successfully joined, or an error if the node could not be reached.

Source

pub async fn join_many( &self, existing: impl Iterator<Item = Node<<T as Transport>::Id, MaybeResolvedAddress<<T as Transport>::Address, <T as Transport>::ResolvedAddress>>>, ) -> Result<SmallVec<Node<<T as Transport>::Id, <T as Transport>::ResolvedAddress>>, (SmallVec<Node<<T as Transport>::Id, <T as Transport>::ResolvedAddress>>, Error<T, D>)>

Available on crate feature tokio only.

Used to take an existing Memberlist and attempt to join a cluster by contacting all the given hosts and performing a state sync. Initially, the Memberlist only contains our own state, so doing this will cause remote nodes to become aware of the existence of this node, effectively joining the cluster.

On success, returns a list of all nodes that were successfully joined with resolved addresses. On error, returns a list of nodes are successfully joined with resolved addresses and the error.

Source

pub fn health_score(&self) -> usize

Available on crate feature tokio only.

Gives this instance’s idea of how well it is meeting the soft real-time requirements of the protocol. Lower numbers are better, and zero means “totally healthy”.

Source

pub async fn update_node(&self, timeout: Duration) -> Result<(), Error<T, D>>

Available on crate feature tokio only.

Used to trigger re-advertising the local node. This is primarily used with a Delegate to support dynamic updates to the local meta data. This will block until the update message is successfully broadcasted to a member of the cluster, if any exist or until a specified timeout is reached.

Source

pub async fn send( &self, to: &<T as Transport>::ResolvedAddress, msg: Bytes, ) -> Result<(), Error<T, D>>

Available on crate feature tokio only.

Uses the unreliable packet-oriented interface of the transport to target a user message at the given node (this does not use the gossip mechanism). The maximum size of the message depends on the configured packet_buffer_size for this memberlist instance.

See also send_reliable.

Source

pub async fn send_many( &self, to: &<T as Transport>::ResolvedAddress, msgs: impl Iterator<Item = Bytes>, ) -> Result<(), Error<T, D>>

Available on crate feature tokio only.

Uses the unreliable packet-oriented interface of the transport to target a user message at the given node (this does not use the gossip mechanism). The maximum size of the message depends on the configured packet_buffer_size for this memberlist instance.

Source

pub async fn send_reliable( &self, to: &<T as Transport>::ResolvedAddress, msg: Bytes, ) -> Result<(), Error<T, D>>

Available on crate feature tokio only.

Uses the reliable stream-oriented interface of the transport to target a user message at the given node (this does not use the gossip mechanism). Delivery is guaranteed if no error is returned, and there is no limit on the size of the message.

See also send_many_reliable.

Source

pub async fn send_many_reliable( &self, to: &<T as Transport>::ResolvedAddress, msgs: impl Iterator<Item = Bytes>, ) -> Result<(), Error<T, D>>

Available on crate feature tokio only.

Uses the reliable stream-oriented interface of the transport to target a user message at the given node (this does not use the gossip mechanism). Delivery is guaranteed if no error is returned, and there is no limit on the size of the message.

Source

pub async fn ping( &self, node: Node<<T as Transport>::Id, <T as Transport>::ResolvedAddress>, ) -> Result<Duration, Error<T, D>>

Available on crate feature tokio only.

Initiates a ping to the node with the specified node.

Source

pub async fn shutdown(&self) -> Result<(), Error<T, D>>

Available on crate feature tokio only.

Stop any background maintenance of network activity for this memberlist, causing it to appear “dead”. A leave message will not be broadcasted prior, so the cluster being left will have to detect this node’s shutdown using probing. If you wish to more gracefully exit the cluster, call Leave prior to shutting down.

This method is safe to call multiple times.

Trait Implementations§

Source§

impl<T, D> Clone for Memberlist<T, D>
where T: Transport, D: Delegate<Id = <T as Transport>::Id, Address = <T as Transport>::ResolvedAddress>,

Source§

fn clone(&self) -> Memberlist<T, D>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<T, D> Freeze for Memberlist<T, D>

§

impl<T, D = VoidDelegate<<T as Transport>::Id, <<T as Transport>::Resolver as AddressResolver>::ResolvedAddress>> !RefUnwindSafe for Memberlist<T, D>

§

impl<T, D> Send for Memberlist<T, D>

§

impl<T, D> Sync for Memberlist<T, D>

§

impl<T, D> Unpin for Memberlist<T, D>

§

impl<T, D = VoidDelegate<<T as Transport>::Id, <<T as Transport>::Resolver as AddressResolver>::ResolvedAddress>> !UnwindSafe for Memberlist<T, D>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more