ElectionCore

Trait ElectionCore 

Source
pub trait ElectionCore<T>:
    Send
    + Sync
    + 'static
where T: TypeConfig,
{ // Required methods fn broadcast_vote_requests<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, term: u64, membership: Arc<MOF<T>>, raft_log: &'life1 Arc<ROF<T>>, transport: &'life2 Arc<TROF<T>>, settings: &'life3 Arc<RaftNodeConfig>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait; fn handle_vote_request<'life0, 'life1, 'async_trait>( &'life0 self, request: VoteRequest, current_term: u64, voted_for_option: Option<VotedFor>, raft_log: &'life1 Arc<ROF<T>>, ) -> Pin<Box<dyn Future<Output = Result<StateUpdate>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn check_vote_request_is_legal( &self, request: &VoteRequest, current_term: u64, last_log_index: u64, last_log_term: u64, voted_for_option: Option<VotedFor>, ) -> bool; }

Required Methods§

Source

fn broadcast_vote_requests<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, term: u64, membership: Arc<MOF<T>>, raft_log: &'life1 Arc<ROF<T>>, transport: &'life2 Arc<TROF<T>>, settings: &'life3 Arc<RaftNodeConfig>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Sends vote requests to all voting members. Returns Ok() if majority votes are received, otherwise returns Err. Initiates RPC calls via transport and evaluates collected responses.

A vote can be granted only if all the following conditions are met:

  • The requests term is greater than the current_term.
  • The candidates log is sufficiently up-to-date.
  • The current node has not voted in the current term or has already voted for the candidate.
Source

fn handle_vote_request<'life0, 'life1, 'async_trait>( &'life0 self, request: VoteRequest, current_term: u64, voted_for_option: Option<VotedFor>, raft_log: &'life1 Arc<ROF<T>>, ) -> Pin<Box<dyn Future<Output = Result<StateUpdate>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Processes incoming vote requests: validates request legality via check_vote_request_is_legal, updates node state if valid, triggers role transition to Follower when granting vote.

If there is a state update, we delegate the update to the parent RoleState instead of updating it within this function.

Validates vote request against Raft rules:

  1. Requester’s term must be ≥ current term
  2. Requester’s log must be at least as recent as local log
  3. Node hasn’t voted for another candidate in current term

Implementors§

Source§

impl<T> ElectionCore<T> for ElectionHandler<T>
where T: TypeConfig,