Struct raft_consensus::consensus::Consensus [−][src]
pub struct Consensus<L, M> { /* fields omitted */ }
An instance of a Raft state machine. The Consensus controls a client state machine, to which it applies entries in a globally consistent order.
Each event incoming from outside, like timer or a consensus packet, shoould be passed to corresponsing finction in consensus along with the handler implementation. Then handler functions will be called when corresponsing events happen
Methods
impl<L, M> Consensus<L, M> where
L: Log,
M: StateMachine,
[src]
impl<L, M> Consensus<L, M> where
L: Log,
M: StateMachine,
pub fn new(
id: ServerId,
peers: Vec<ServerId>,
log: L,
state_machine: M
) -> Result<Self, Error>
[src]
pub fn new(
id: ServerId,
peers: Vec<ServerId>,
log: L,
state_machine: M
) -> Result<Self, Error>
Creates a Consensus
.
pub fn init<H: ConsensusHandler>(&mut self, handler: &mut H)
[src]
pub fn init<H: ConsensusHandler>(&mut self, handler: &mut H)
Calls initial actions which should be executed upon startup.
pub fn apply_peer_message<H: ConsensusHandler>(
&mut self,
handler: &mut H,
from: ServerId,
message: PeerMessage
) -> Result<(), Error>
[src]
pub fn apply_peer_message<H: ConsensusHandler>(
&mut self,
handler: &mut H,
from: ServerId,
message: PeerMessage
) -> Result<(), Error>
Applies a peer message to the consensus state machine.
impl<L, M> Consensus<L, M> where
L: Log,
M: StateMachine,
[src]
impl<L, M> Consensus<L, M> where
L: Log,
M: StateMachine,
Client messages processing
pub fn apply_client_message<H: ConsensusHandler>(
&mut self,
handler: &mut H,
from: ClientId,
message: ClientRequest
) -> Result<(), Error>
[src]
pub fn apply_client_message<H: ConsensusHandler>(
&mut self,
handler: &mut H,
from: ClientId,
message: ClientRequest
) -> Result<(), Error>
Applies a client message to the consensus state machine.
impl<L, M> Consensus<L, M> where
L: Log,
M: StateMachine,
[src]
impl<L, M> Consensus<L, M> where
L: Log,
M: StateMachine,
Timeout handling
pub fn apply_timeout<H: ConsensusHandler>(
&mut self,
handler: &mut H,
timeout: ConsensusTimeout
) -> Result<(), Error>
[src]
pub fn apply_timeout<H: ConsensusHandler>(
&mut self,
handler: &mut H,
timeout: ConsensusTimeout
) -> Result<(), Error>
Triggered by external timeouts.
Convenience function for handling any timeout.
Will call either heartbeat_timeout
or election_timeout
pub fn heartbeat_timeout(
&mut self,
peer: ServerId
) -> Result<AppendEntriesRequest, Error>
[src]
pub fn heartbeat_timeout(
&mut self,
peer: ServerId
) -> Result<AppendEntriesRequest, Error>
Triggered by a heartbeat timeout for the peer.
pub fn election_timeout<H: ConsensusHandler>(
&mut self,
handler: &mut H
) -> Result<(), Error>
[src]
pub fn election_timeout<H: ConsensusHandler>(
&mut self,
handler: &mut H
) -> Result<(), Error>
Triggered by an election timeout.
impl<L, M> Consensus<L, M> where
L: Log,
M: StateMachine,
[src]
impl<L, M> Consensus<L, M> where
L: Log,
M: StateMachine,
Utility functions
pub fn peer_connected<H: ConsensusHandler>(
&mut self,
handler: &mut H,
peer: ServerId
) -> Result<(), Error>
[src]
pub fn peer_connected<H: ConsensusHandler>(
&mut self,
handler: &mut H,
peer: ServerId
) -> Result<(), Error>
pub fn get_state(&self) -> ConsensusState
[src]
pub fn get_state(&self) -> ConsensusState
Returns current state of consensus state machine
Trait Implementations
impl<L: Debug, M: Debug> Debug for Consensus<L, M>
[src]
impl<L: Debug, M: Debug> Debug for Consensus<L, M>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<L: Clone, M: Clone> Clone for Consensus<L, M>
[src]
impl<L: Clone, M: Clone> Clone for Consensus<L, M>