use crate::storage::{
BeginScanOptions, Capability, CommitResult, GetManyRequest, GetManyResult, Key, KeyRange,
PutBatch, ReadOptions, ScanCursor, StorageChangeWatch, StorageError, StorageSpace,
StorageSessionToken, WriteOptions,
};
pub trait Storage: Send + Sync {
type Read<'a>: StorageRead + 'a
where
Self: 'a;
type Write<'a>: StorageWrite + 'a
where
Self: 'a;
fn acquire_session(
&self,
) -> impl Future<Output = Result<StorageSessionToken, StorageError>> + Send;
fn begin_read(
&self,
opts: ReadOptions,
) -> impl Future<Output = Result<Self::Read<'_>, StorageError>> + Send;
fn begin_write(
&self,
opts: WriteOptions,
) -> impl Future<Output = Result<Self::Write<'_>, StorageError>> + Send;
fn watch_for_changes(
&self,
) -> impl Future<Output = Result<StorageChangeWatch, StorageError>> + Send {
async { Err(StorageError::Unsupported(Capability::ChangeWatch)) }
}
}
pub trait StorageRead: Send + Sync {
fn snapshot_cache_key(&self) -> Option<u128> {
None
}
fn get_many(
&self,
requests: &[GetManyRequest<'_>],
) -> impl Future<Output = Result<GetManyResult, StorageError>> + Send;
fn begin_scan(
&self,
space: StorageSpace,
range: KeyRange,
opts: BeginScanOptions,
) -> impl Future<Output = Result<ScanCursor<'_>, StorageError>> + Send;
}
pub trait StorageWrite: Send {
fn put_many(
&mut self,
space: StorageSpace,
entries: PutBatch,
) -> impl Future<Output = Result<(), StorageError>> + Send;
fn replace_many(
&mut self,
space: StorageSpace,
entries: PutBatch,
) -> impl Future<Output = Result<(), StorageError>> + Send;
fn delete_many(
&mut self,
space: StorageSpace,
keys: &[Key],
) -> impl Future<Output = Result<(), StorageError>> + Send;
fn delete_range(
&mut self,
space: StorageSpace,
range: KeyRange,
) -> impl Future<Output = Result<(), StorageError>> + Send;
fn commit(self) -> impl Future<Output = Result<CommitResult, StorageError>> + Send;
fn rollback(self) -> impl Future<Output = Result<(), StorageError>> + Send;
}