dcs2_raft/
lib.rs

1//! # Raft coordination module
2//! This module is designed to be used as the coordination component in the [`dcs`] framework.
3//! It implements the [raft algorithm](https://raft.github.io/).
4//! It's main export is the [`RaftSDK`] including the [`RaftService`].
5//!
6#![allow(warnings)]
7
8use clock::OsClock;
9use core::fmt::{Display, Formatter};
10use dcs::coordination::Stopwatch;
11use dcs::heapless::LinearMap;
12use dcs::membership::metadata::{BasicMetadata, SerializableMetadata};
13use dcs::nodes::{CoordinationSDK, SystemNodeId};
14use dcs::properties::CLUSTER_NODE_COUNT;
15use dcs::rules::measurements::Measurement;
16use serde::*;
17
18use crate::messages::{RaftMessage, RaftPackageBuilder};
19use crate::metadata::{RaftMetadata, RaftMetadataBuilder};
20use crate::server::RaftService;
21use crate::state::RaftState;
22
23pub mod messages;
24pub mod metadata;
25pub mod server;
26pub mod state;
27
28pub static ELECTION_TIMEOUT: u64 = 15000;
29pub static CANDIATE_ELECTION_TIMEOUT: u64 = 10000;
30
31pub struct RaftSDK;
32
33impl CoordinationSDK for RaftSDK {
34    type Clock = OsClock;
35    type Members = LinearMap<SystemNodeId, RaftMetadata, CLUSTER_NODE_COUNT>;
36    type Message = RaftMessage<RaftState>;
37    type Metadata = RaftMetadata;
38    type Service = RaftService<Self::Clock, RaftState>;
39    type PackageBuilder = RaftPackageBuilder<RaftState>;
40    type MetadataBuilder = RaftMetadataBuilder;
41}