mod default_state_machine_handler;
mod snapshot_assembler;
mod snapshot_guard;
mod snapshot_policy;
mod worker;
pub use default_state_machine_handler::*;
pub(crate) use snapshot_assembler::*;
pub(crate) use snapshot_guard::*;
pub use snapshot_policy::*;
pub use worker::*;
#[cfg(test)]
mod default_state_machine_handler_test;
#[cfg(test)]
mod snapshot_assembler_test;
#[cfg(test)]
mod wait_applied_test;
#[cfg(test)]
mod worker_test;
use d_engine_proto::client::ClientResult;
use d_engine_proto::server::storage::SnapshotChunk;
use d_engine_proto::server::storage::SnapshotMetadata;
use futures::stream::BoxStream;
#[cfg(any(test, feature = "__test_support"))]
use mockall::automock;
use tonic::async_trait;
use super::NewCommitData;
use crate::ApplyResult;
use crate::Result;
use crate::TypeConfig;
#[cfg_attr(any(test, feature = "__test_support"), automock)]
#[async_trait]
pub trait StateMachineHandler<T>: Send + Sync + 'static
where
T: TypeConfig,
{
fn last_applied(&self) -> u64;
fn update_pending(
&self,
new_commit: u64,
);
async fn wait_applied(
&self,
target_index: u64,
timeout: std::time::Duration,
) -> Result<()>;
async fn apply_chunk(
&self,
chunk: Vec<d_engine_proto::common::Entry>,
) -> Result<Vec<ApplyResult>>;
fn read_from_state_machine(
&self,
keys: Vec<bytes::Bytes>,
) -> Option<Vec<ClientResult>>;
async fn apply_snapshot_stream_from_leader(
&self,
current_term: u64,
stream: Box<tonic::Streaming<SnapshotChunk>>,
ack_tx: tokio::sync::mpsc::Sender<d_engine_proto::server::storage::SnapshotAck>,
config: &crate::SnapshotConfig,
) -> Result<()>;
fn should_snapshot(
&self,
new_commit_data: NewCommitData,
) -> bool;
async fn create_snapshot(&self) -> Result<(SnapshotMetadata, std::path::PathBuf)>;
async fn cleanup_snapshot(
&self,
before_version: u64,
snapshot_dir: &std::path::Path,
snapshot_dir_prefix: &str,
) -> crate::Result<()>;
fn get_latest_snapshot_metadata(&self) -> Option<SnapshotMetadata>;
async fn load_snapshot_data(
&self,
metadata: SnapshotMetadata,
) -> Result<BoxStream<'static, Result<SnapshotChunk>>>;
#[allow(unused)]
async fn load_snapshot_chunk(
&self,
metadata: &SnapshotMetadata,
seq: u32,
) -> Result<SnapshotChunk>;
fn pending_range(&self) -> Option<std::ops::RangeInclusive<u64>>;
}