pub mod durable_store;
pub mod lease;
pub mod network;
pub mod state_machine;
pub mod store;
pub mod types;
pub use durable_store::DurableLogStore;
pub use lease::ConsolidationLease;
pub use state_machine::HirnStateMachine;
pub use store::DevMemLogStore;
pub use types::*;
use std::sync::Arc;
use openraft::Config;
pub fn default_raft_config() -> Config {
Config {
heartbeat_interval: 150,
election_timeout_min: 300,
election_timeout_max: 500,
snapshot_policy: openraft::SnapshotPolicy::LogsSinceLast(1000),
..Config::default()
}
}
pub type HirnRaft = openraft::Raft<TypeConfig>;
pub async fn new_raft(
node_id: NodeId,
config: Arc<Config>,
log_store: DurableLogStore,
state_machine: Arc<HirnStateMachine>,
network: network::HirnRaftNetworkFactory,
) -> Result<HirnRaft, openraft::error::Fatal<NodeId>> {
openraft::Raft::new(node_id, config, network, log_store, state_machine).await
}
pub async fn new_raft_dev(
node_id: NodeId,
config: Arc<Config>,
log_store: DevMemLogStore,
state_machine: Arc<HirnStateMachine>,
network: network::HirnRaftNetworkFactory,
) -> Result<HirnRaft, openraft::error::Fatal<NodeId>> {
openraft::Raft::new(node_id, config, network, log_store, state_machine).await
}