use crate::StorageRead;
use crate::coordinator::WriteCommand;
use crate::storage::StorageSnapshot;
use async_trait::async_trait;
use std::ops::Range;
use std::sync::Arc;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Durability {
Applied,
Written,
Durable,
}
pub trait Delta: Sized + Send + Sync + 'static {
type Context: Send + Sync + 'static;
type Write: Send + 'static;
type Frozen: Send + Sync + 'static;
type FrozenView: Clone + Send + Sync + 'static;
type ApplyResult: Clone + Send + 'static;
type DeltaView: Clone + Send + Sync + 'static;
fn init(context: Self::Context) -> Self;
fn apply(&mut self, write: Self::Write) -> Result<Self::ApplyResult, String>;
fn estimate_size(&self) -> usize;
fn freeze(self) -> (Self::Frozen, Self::FrozenView, Self::Context);
fn reader(&self) -> Self::DeltaView;
}
#[derive(Clone)]
pub struct EpochStamped<T> {
pub val: T,
pub epoch_range: Range<u64>,
}
impl<T> EpochStamped<T> {
pub(crate) fn new(val: T, epoch_range: Range<u64>) -> Self {
Self { val, epoch_range }
}
}
#[async_trait]
pub trait Flusher<D: Delta>: Send + Sync + 'static {
async fn flush_delta(
&mut self,
frozen: D::Frozen,
epoch_range: &Range<u64>,
) -> Result<Arc<dyn StorageSnapshot>, String>;
async fn flush_storage(&self) -> Result<(), String>;
}