use crate::error::Result;
use std::path::Path;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum BackendPartition {
Default,
TombstoneStorage,
CompressedArchive,
Tombstones,
NamespaceIndex,
PayloadIndex,
TextIndex,
InternalMetadata,
}
impl BackendPartition {
pub(crate) fn cf_name(&self) -> &'static str {
match self {
BackendPartition::Default => "default",
BackendPartition::TombstoneStorage => "tombstone_storage",
BackendPartition::CompressedArchive => "compressed_archive",
BackendPartition::Tombstones => "tombstones",
BackendPartition::NamespaceIndex => "namespace_index",
BackendPartition::PayloadIndex => "payload_index",
BackendPartition::TextIndex => "text_index",
BackendPartition::InternalMetadata => "internal_metadata",
}
}
}
#[derive(Clone)]
pub(crate) enum BackendWriteOp {
#[allow(dead_code)]
Put {
partition: BackendPartition,
key: Vec<u8>,
value: Vec<u8>,
},
Delete {
partition: BackendPartition,
key: Vec<u8>,
},
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum BackendKind {
RocksDb,
#[default]
Fjall,
InMemory,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BackendCapabilities {
pub supports_checkpoint: bool,
pub supports_manual_compaction: bool,
pub kind: BackendKind,
}
pub(crate) trait StorageBackend: Send + Sync {
fn put(&self, partition: BackendPartition, key: &[u8], value: &[u8]) -> Result<()>;
fn get(&self, partition: BackendPartition, key: &[u8]) -> Result<Option<Vec<u8>>>;
fn delete(&self, partition: BackendPartition, key: &[u8]) -> Result<()>;
fn write_batch(&self, ops: Vec<BackendWriteOp>) -> Result<()>;
fn scan(&self, partition: BackendPartition) -> Result<Vec<(Vec<u8>, Vec<u8>)>>;
fn scan_prefix(
&self,
partition: BackendPartition,
prefix: &[u8],
) -> Result<Vec<(Vec<u8>, Vec<u8>)>>;
fn flush(&self) -> Result<()> {
Ok(())
}
fn checkpoint(&self, path: &Path) -> Result<()>;
fn compact(&self) {
}
fn capabilities(&self) -> BackendCapabilities;
}