Struct Serf

Source
pub struct Serf<T, D = DefaultDelegate<T>>
where D: Delegate<Id = T::Id, Address = T::ResolvedAddress>, T: Transport,
{ /* private fields */ }
Expand description

Serf is a single node that is part of a single cluster that gets events about joins/leaves/failures/etc. It is created with the Create method.

All functions on the Serf structure are safe to call concurrently.

Implementations§

Source§

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

Source

pub async fn new( transport: T::Options, opts: Options, ) -> Result<Self, Error<T, DefaultDelegate<T>>>

Creates a new Serf instance with the given transport and options.

Source

pub async fn with_event_producer( transport: T::Options, opts: Options, ev: EventProducer<T, DefaultDelegate<T>>, ) -> Result<Self, Error<T, DefaultDelegate<T>>>

Creates a new Serf instance with the given transport and options.

Source§

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

Source

pub async fn with_delegate( transport: T::Options, opts: Options, delegate: D, ) -> Result<Self, Error<T, D>>

Creates a new Serf instance with the given transport and options.

Source

pub async fn with_event_producer_and_delegate( transport: T::Options, opts: Options, ev: EventProducer<T, D>, delegate: D, ) -> Result<Self, Error<T, D>>

Creates a new Serf instance with the given transport, options, event sender, and delegate.

Source

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

Returns the local node’s ID

Source

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

Returns the local node’s ID and the advertised address

Source

pub fn encryption_enabled(&self) -> bool

Available on crate feature encryption only.

A predicate that determines whether or not encryption is enabled, which can be possible in one of 2 cases:

  • Single encryption key passed at agent start (no persistence)
  • Keyring file provided at agent start
Source

pub fn shutdown_rx(&self) -> Receiver<()>

Returns a receiver that can be used to wait for Serf to shutdown.

Source

pub fn state(&self) -> SerfState

The current state of this Serf instance.

Source

pub async fn members(&self) -> OneOrMore<Member<T::Id, T::ResolvedAddress>>

Returns a point-in-time snapshot of the members of this cluster.

Source

pub async fn stats(&self) -> Stats

Used to provide operator debugging information

Source

pub async fn num_members(&self) -> usize

Returns the number of nodes in the serf cluster, regardless of their health or status.

Source

pub fn key_manager(&self) -> &KeyManager<T, D>

Available on crate feature encryption only.

Returns the key manager for the current serf instance

Source

pub async fn local_member(&self) -> Member<T::Id, T::ResolvedAddress>

Returns the Member information for the local node

Source

pub async fn set_tags(&self, tags: Tags) -> Result<(), Error<T, D>>

Used to dynamically update the tags associated with the local node. This will propagate the change to the rest of the cluster. Blocks until a the message is broadcast out.

Source

pub async fn user_event( &self, name: impl Into<SmolStr>, payload: impl Into<Bytes>, coalesce: bool, ) -> Result<(), Error<T, D>>

Used to broadcast a custom user event with a given name and payload. If the configured size limit is exceeded and error will be returned. If coalesce is enabled, nodes are allowed to coalesce this event.

Source

pub async fn query( &self, name: impl Into<SmolStr>, payload: impl Into<Bytes>, params: Option<QueryParam<T::Id>>, ) -> Result<QueryResponse<T::Id, T::ResolvedAddress>, Error<T, D>>

Used to broadcast a new query. The query must be fairly small, and an error will be returned if the size limit is exceeded. Query parameters are optional, and if not provided, a sane set of defaults will be used.

Source

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

Joins an existing Serf cluster. Returns the id of node successfully contacted. If ignore_old is true, then any user messages sent prior to the join will be ignored.

Source

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

Joins an existing Serf cluster. Returns the id of nodes successfully contacted. If ignore_old is true, then any user messages sent prior to the join will be ignored.

Source

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

Gracefully exits the cluster. It is safe to call this multiple times. If the Leave broadcast timeout, Leave() will try to finish the sequence as best effort.

Source

pub async fn remove_failed_node(&self, id: T::Id) -> Result<(), Error<T, D>>

Forcibly removes a failed node from the cluster immediately, instead of waiting for the reaper to eventually reclaim it. This also has the effect that Serf will no longer attempt to reconnect to this node.

Source

pub async fn remove_failed_node_prune( &self, id: T::Id, ) -> Result<(), Error<T, D>>

Forcibly removes a failed node from the cluster immediately, instead of waiting for the reaper to eventually reclaim it. This also has the effect that Serf will no longer attempt to reconnect to this node.

Source

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

Forcefully shuts down the Serf instance, stopping all network activity and background maintenance associated with the instance.

This is not a graceful shutdown, and should be preceded by a call to Leave. Otherwise, other nodes in the cluster will detect this node’s exit as a node failure.

It is safe to call this method multiple times.

Source

pub fn cooridate(&self) -> Result<Coordinate, Error<T, D>>

Returns the network coordinate of the local node.

Source

pub fn cached_coordinate( &self, id: &T::Id, ) -> Result<Option<Coordinate>, Error<T, D>>

Returns the network coordinate for the node with the given name. This will only be valid if disable_coordinates is set to false.

Source

pub fn memberlist(&self) -> &Memberlist<T, SerfDelegate<T, D>>

Returns the underlying Memberlist instance

Source§

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

Source

pub async fn default_query_timeout(&self) -> Duration

Returns the default timeout value for a query Computed as

gossip_interval * query_timeout_mult * log(N+1)
Source

pub async fn default_query_param(&self) -> QueryParam<T::Id>

Used to return the default query parameters

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> Self

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

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T, D = CompositeDelegate<<T as Transport>::Id, <<T as Transport>::Resolver as AddressResolver>::ResolvedAddress>> !UnwindSafe for Serf<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
Source§

impl<T> ErasedDestructor for T
where T: 'static,