Skip to main content

GossipEngine

Struct GossipEngine 

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

The gossip engine manages cluster membership and failure detection.

Implementations§

Source§

impl GossipEngine

Source

pub fn new( local_id: NodeId, local_addr: SocketAddr, config: GossipConfig, event_tx: Sender<GossipEvent>, ) -> Self

Creates a new gossip engine.

Source

pub fn local_id(&self) -> NodeId

Returns the local node ID.

Source

pub fn local_incarnation(&self) -> u64

Returns the local node’s incarnation number.

Source

pub fn set_incarnation(&mut self, n: u64)

Restores the incarnation number from a previous session.

Used when loading persisted config so the node doesn’t regress to a lower incarnation, which would make it lose suspicion refutations.

Source

pub fn members(&self) -> impl Iterator<Item = &MemberState>

Returns all known members.

Source

pub fn alive_member_addrs(&self) -> Vec<SocketAddr>

Returns gossip addresses for all currently alive members.

Source

pub fn alive_count(&self) -> usize

Returns the number of alive members (excluding self).

Source

pub fn set_local_slots(&mut self, slots: Vec<SlotRange>)

Updates the local node’s slot ownership.

Called after ADDSLOTS/DELSLOTS/SETSLOT NODE to keep the gossip engine’s view in sync. The updated slots are included in Welcome replies so joining nodes learn the full slot map.

Source

pub fn queue_slots_update( &mut self, node: NodeId, incarnation: u64, slots: Vec<SlotRange>, )

Queues a slot ownership update for gossip propagation.

The update will be piggybacked on the next outgoing Ping or Ack message, spreading to the cluster via epidemic dissemination.

Source

pub fn queue_role_update( &mut self, node: NodeId, incarnation: u64, is_primary: bool, replicates: Option<NodeId>, )

Queues a role change for gossip propagation.

Called after this node changes from primary to replica (or vice versa). The update will be piggybacked on the next outgoing Ping or Ack.

Source

pub fn queue_vote_request(&mut self, candidate: NodeId, epoch: u64, offset: u64)

Queues a vote request for gossip propagation.

Called by a replica that is starting an automatic failover election. The update will be piggybacked on the next outgoing Ping or Ack.

Source

pub fn queue_vote_granted( &mut self, from: NodeId, candidate: NodeId, epoch: u64, )

Queues a vote grant for gossip propagation.

Called by a primary that has decided to vote for the given candidate. The update will be piggybacked on the next outgoing Ping or Ack.

Source

pub fn add_seed(&mut self, id: NodeId, addr: SocketAddr)

Adds a seed node to bootstrap cluster discovery.

Source

pub async fn handle_message( &mut self, msg: GossipMessage, from: SocketAddr, ) -> Vec<(SocketAddr, GossipMessage)>

Handles an incoming gossip message.

Returns a list of (address, message) pairs to send. Most messages produce a single reply back to from, but PingReq forwards a Ping to a different host, and relayed Acks route back to the original requester.

Source

pub fn tick(&mut self) -> Vec<(SocketAddr, GossipMessage)>

Runs one protocol period: probe a random node.

Returns all messages to send this tick: the direct probe plus any PingReq messages generated by timed-out direct probes.

Source

pub fn create_join_message(&self) -> GossipMessage

Creates a join message to send to a seed node.

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> 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> 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> Same for T

Source§

type Output = T

Should always be Self
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> 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> OptionalSend for T
where T: Send + ?Sized,

Source§

impl<T> OptionalSync for T
where T: Sync + ?Sized,