pub struct GossipEngine { /* private fields */ }Expand description
The gossip engine manages cluster membership and failure detection.
Implementations§
Source§impl GossipEngine
impl GossipEngine
Sourcepub fn new(
local_id: NodeId,
local_addr: SocketAddr,
config: GossipConfig,
event_tx: Sender<GossipEvent>,
) -> Self
pub fn new( local_id: NodeId, local_addr: SocketAddr, config: GossipConfig, event_tx: Sender<GossipEvent>, ) -> Self
Creates a new gossip engine.
Sourcepub fn local_incarnation(&self) -> u64
pub fn local_incarnation(&self) -> u64
Returns the local node’s incarnation number.
Sourcepub fn set_incarnation(&mut self, n: u64)
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.
Sourcepub fn members(&self) -> impl Iterator<Item = &MemberState>
pub fn members(&self) -> impl Iterator<Item = &MemberState>
Returns all known members.
Sourcepub fn alive_member_addrs(&self) -> Vec<SocketAddr>
pub fn alive_member_addrs(&self) -> Vec<SocketAddr>
Returns gossip addresses for all currently alive members.
Sourcepub fn alive_count(&self) -> usize
pub fn alive_count(&self) -> usize
Returns the number of alive members (excluding self).
Sourcepub fn set_local_slots(&mut self, slots: Vec<SlotRange>)
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.
Sourcepub fn queue_slots_update(
&mut self,
node: NodeId,
incarnation: u64,
slots: Vec<SlotRange>,
)
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.
Sourcepub fn queue_role_update(
&mut self,
node: NodeId,
incarnation: u64,
is_primary: bool,
replicates: Option<NodeId>,
)
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.
Sourcepub fn queue_vote_request(&mut self, candidate: NodeId, epoch: u64, offset: u64)
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.
Sourcepub fn queue_vote_granted(
&mut self,
from: NodeId,
candidate: NodeId,
epoch: u64,
)
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.
Sourcepub fn add_seed(&mut self, id: NodeId, addr: SocketAddr)
pub fn add_seed(&mut self, id: NodeId, addr: SocketAddr)
Adds a seed node to bootstrap cluster discovery.
Sourcepub async fn handle_message(
&mut self,
msg: GossipMessage,
from: SocketAddr,
) -> Vec<(SocketAddr, GossipMessage)>
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.
Sourcepub fn tick(&mut self) -> Vec<(SocketAddr, GossipMessage)>
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.
Sourcepub fn create_join_message(&self) -> GossipMessage
pub fn create_join_message(&self) -> GossipMessage
Creates a join message to send to a seed node.