use crate::error::Result;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StorageProfile {
Default,
Mobile,
Server,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StorageEngine {
Sled,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct StorageOptions {
pub engine: StorageEngine,
pub profile: StorageProfile,
}
impl Default for StorageOptions {
fn default() -> Self {
Self {
engine: StorageEngine::Sled,
profile: StorageProfile::Default,
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct StorageTuning {
pub cache_capacity_bytes: Option<u64>,
pub flush_every_ms: Option<u64>,
pub use_compression: bool,
}
impl StorageProfile {
pub fn tuning(self) -> StorageTuning {
match self {
StorageProfile::Default => StorageTuning {
cache_capacity_bytes: None,
flush_every_ms: Some(1000),
use_compression: false,
},
StorageProfile::Mobile => StorageTuning {
cache_capacity_bytes: Some(16 * 1024 * 1024),
flush_every_ms: Some(3000),
use_compression: false,
},
StorageProfile::Server => StorageTuning {
cache_capacity_bytes: Some(256 * 1024 * 1024),
flush_every_ms: Some(500),
use_compression: true,
},
}
}
}
pub trait StorageBackend: Send + Sync {
fn backend_name(&self) -> &'static str;
fn profile(&self) -> StorageProfile;
fn tuning(&self) -> StorageTuning {
self.profile().tuning()
}
fn verify_health(&self) -> Result<()> {
Ok(())
}
fn supports_node_batch_scan(&self) -> bool {
true
}
fn estimated_cache_capacity_bytes(&self) -> Option<u64> {
self.tuning().cache_capacity_bytes
}
fn repair_metadata_if_needed(&self) -> Result<()> {
Ok(())
}
}