1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//! # Raft coordination module
//! This module is designed to be used as the coordination component in the [`dcs`] framework.
//! It implements the [raft algorithm](https://raft.github.io/).
//! It's main export is the [`RaftSDK`] including the [`RaftService`].
//!
#![allow(warnings)]

use clock::OsClock;
use core::fmt::{Display, Formatter};
use dcs::coordination::Stopwatch;
use dcs::heapless::LinearMap;
use dcs::membership::metadata::{BasicMetadata, SerializableMetadata};
use dcs::nodes::{CoordinationSDK, SystemNodeId};
use dcs::properties::CLUSTER_NODE_COUNT;
use dcs::rules::measurements::Measurement;
use serde::*;

use crate::messages::{RaftMessage, RaftPackageBuilder};
use crate::metadata::{RaftMetadata, RaftMetadataBuilder};
use crate::server::RaftService;
use crate::state::RaftState;

pub mod messages;
pub mod metadata;
pub mod server;
pub mod state;

pub static ELECTION_TIMEOUT: u64 = 15000;
pub static CANDIATE_ELECTION_TIMEOUT: u64 = 10000;

pub struct RaftSDK;

impl CoordinationSDK for RaftSDK {
    type Clock = OsClock;
    type Members = LinearMap<SystemNodeId, RaftMetadata, CLUSTER_NODE_COUNT>;
    type Message = RaftMessage<RaftState>;
    type Metadata = RaftMetadata;
    type Service = RaftService<Self::Clock, RaftState>;
    type PackageBuilder = RaftPackageBuilder<RaftState>;
    type MetadataBuilder = RaftMetadataBuilder;
}