use async_trait::async_trait;
use bytes::Bytes;
#[derive(Debug, thiserror::Error)]
pub enum StateBackendError {
#[error("I/O error: {0}")]
Io(String),
#[error("serialization error: {0}")]
Serialization(String),
#[error("not found: vnode={vnode} epoch={epoch}")]
NotFound {
vnode: u32,
epoch: u64,
},
#[error("stale assignment version: caller={caller} < authoritative={authoritative}")]
StaleVersion {
caller: u64,
authoritative: u64,
},
#[error(
"split-brain commit detected: epoch already committed by {committer:?}, we are {self_id:?}"
)]
SplitBrainCommit {
committer: String,
self_id: String,
},
}
#[async_trait]
pub trait StateBackend: Send + Sync + 'static {
async fn write_partial(
&self,
vnode: u32,
epoch: u64,
assignment_version: u64,
bytes: Bytes,
) -> Result<(), StateBackendError>;
async fn read_partial(
&self,
vnode: u32,
epoch: u64,
) -> Result<Option<Bytes>, StateBackendError>;
async fn epoch_complete(&self, epoch: u64, vnodes: &[u32]) -> Result<bool, StateBackendError>;
async fn prune_before(&self, before: u64) -> Result<(), StateBackendError>;
async fn latest_committed_epoch(&self) -> Result<Option<u64>, StateBackendError> {
Ok(None)
}
fn set_authoritative_version(&self, _version: u64) {}
fn authoritative_version(&self) -> u64 {
0
}
}
const _: Option<&dyn StateBackend> = None;