Struct dcs2_raft::server::RaftService
source · pub struct RaftService<T: Stopwatch, L: LogData> {
pub members_already_setup: bool,
/* private fields */
}
Expand description
This is the implementation of the CoordinationService
for the raft algorithm.
Fields§
§members_already_setup: bool
Implementations§
source§impl<T: Stopwatch, L: LogData> RaftService<T, L>
impl<T: Stopwatch, L: LogData> RaftService<T, L>
pub fn is_leader(&self) -> bool
pub fn process( &mut self, communication_service: &mut dyn CommunicationService<RaftPackage<L>>, message: Option<Package<SystemNodeId, RaftMessage<L>>>, members: Option<LinearMap<SystemNodeId, RaftMetadata, CLUSTER_NODE_COUNT>> )
pub fn tick( &mut self, communication_service: &mut dyn CommunicationService<RaftPackage<L>> )
pub fn reject_read_request( &mut self, header: Header<SystemNodeId>, communication_service: &mut dyn CommunicationService<RaftPackage<L>> )
pub fn reject_write_request( &mut self, header: Header<SystemNodeId>, communication_service: &mut dyn CommunicationService<RaftPackage<L>> )
pub fn current_config(&self) -> UpdateClusterVec
pub fn update_config(&mut self, new_cluster: &UpdateClusterVec)
pub fn update_commit_index(&mut self)
pub fn replicate_entry( &mut self, entry: LogEntry<L>, communication_service: &mut dyn CommunicationService<RaftPackage<L>> )
Trait Implementations§
source§impl<T: Stopwatch, L: LogData> CoordinationService<T, RaftMessage<L>, LinearMap<SystemNodeId, RaftMetadata, CLUSTER_NODE_COUNT>, RaftMetadata> for RaftService<T, L>
impl<T: Stopwatch, L: LogData> CoordinationService<T, RaftMessage<L>, LinearMap<SystemNodeId, RaftMetadata, CLUSTER_NODE_COUNT>, RaftMetadata> for RaftService<T, L>
source§fn new(id: SystemNodeId, metadata: RaftMetadata) -> Self
fn new(id: SystemNodeId, metadata: RaftMetadata) -> Self
The id
will identify this nodes and the metadata
will be used to obtain the root timeout.
From that value the heartbeat timeout, the candidate timeout, and the follower timeout will be computed
as follows:
- The heartbeat: this is the time between empty
RaftMessage::AppendLog
are sent to the followers is set to be 20% of the root timeout. - The candidate timeout: this is the time candidates will wait for the
RaftMessage::AppendLogResponse
before starting a new election. This is set to be the 75% of the root timeout - Follower timeout: this is the time a follower will wait for heartbeats, this is,
AppendLog
messages. This is set to be equal to the root timeout.
source§fn leader(&self) -> Option<SystemNodeId>
fn leader(&self) -> Option<SystemNodeId>
Returns the ID of the cluster leader, or None if it is not set.
source§fn get_state(&self) -> SystemState
fn get_state(&self) -> SystemState
Returns the coordinated state of the system
source§fn get_current_rule(&self) -> Option<Rule>
fn get_current_rule(&self) -> Option<Rule>
Returns the current rule coordinated by the system
source§fn update_rule(
&mut self,
communication_service: &mut dyn CommunicationService<Package<SystemNodeId, RaftMessage<L>>>,
new_rule: Rule
)
fn update_rule( &mut self, communication_service: &mut dyn CommunicationService<Package<SystemNodeId, RaftMessage<L>>>, new_rule: Rule )
Updates the nodes in the cluster based on [
new_config
].source§fn update_members(
&mut self,
communication_service: &mut dyn CommunicationService<RaftPackage<L>>,
new_config: UpdateClusterVec
)
fn update_members( &mut self, communication_service: &mut dyn CommunicationService<RaftPackage<L>>, new_config: UpdateClusterVec )
Updates the nodes in the cluster based on [
new_config
].source§fn update_state(
&mut self,
communication_service: &mut dyn CommunicationService<RaftPackage<L>>,
measurement: Measurement
)
fn update_state( &mut self, communication_service: &mut dyn CommunicationService<RaftPackage<L>>, measurement: Measurement )
Updates the coordinated state of the system based on
measurement
source§fn process(
&mut self,
communication_service: &mut dyn CommunicationService<RaftPackage<L>>,
package: Option<CoordinationPackage<RaftMessage<L>>>,
members: LinearMap<SystemNodeId, RaftMetadata, CLUSTER_NODE_COUNT>
)
fn process( &mut self, communication_service: &mut dyn CommunicationService<RaftPackage<L>>, package: Option<CoordinationPackage<RaftMessage<L>>>, members: LinearMap<SystemNodeId, RaftMetadata, CLUSTER_NODE_COUNT> )
Receives a message from another node so that the coordination can occur.
Auto Trait Implementations§
impl<T, L> RefUnwindSafe for RaftService<T, L>where
L: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, L> Send for RaftService<T, L>
impl<T, L> Sync for RaftService<T, L>
impl<T, L> Unpin for RaftService<T, L>
impl<T, L> UnwindSafe for RaftService<T, L>where
L: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more