use std::path::PathBuf;
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum Storage {
Persistent {
dir: PathBuf,
},
Memory,
}
#[derive(Debug, Clone)]
pub struct TreeConfig {
pub storage: Storage,
pub buffer_pool_size: usize,
pub wal_sync_on_commit: bool,
pub checkpoint_byte_interval: u64,
pub flush_on_write: bool,
}
impl TreeConfig {
#[must_use]
pub fn new<P: Into<PathBuf>>(dir: P) -> Self {
Self {
storage: Storage::Persistent { dir: dir.into() },
buffer_pool_size: 64,
wal_sync_on_commit: false,
checkpoint_byte_interval: 16 * 1024 * 1024,
flush_on_write: true,
}
}
#[must_use]
pub fn memory() -> Self {
Self {
storage: Storage::Memory,
buffer_pool_size: 64,
wal_sync_on_commit: false,
checkpoint_byte_interval: 16 * 1024 * 1024,
flush_on_write: true,
}
}
#[must_use]
pub fn is_memory(&self) -> bool {
matches!(self.storage, Storage::Memory)
}
#[must_use]
pub fn wal_path(&self) -> Option<PathBuf> {
match &self.storage {
Storage::Persistent { dir } => Some(dir.join("journal.wal")),
Storage::Memory => None,
}
}
}