use std::path::PathBuf;
use crate::checkpoint::CheckpointConfig;
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum Storage {
File {
dir: PathBuf,
},
Memory,
}
#[derive(Debug, Clone)]
pub struct TreeConfig {
pub storage: Storage,
pub buffer_pool_size: usize,
pub wal_sync: bool,
pub memory_flush_on_write: bool,
pub checkpoint: CheckpointConfig,
}
impl TreeConfig {
#[must_use]
pub fn new<P: Into<PathBuf>>(dir: P) -> Self {
Self {
storage: Storage::File { dir: dir.into() },
buffer_pool_size: 64,
wal_sync: false,
memory_flush_on_write: true,
checkpoint: CheckpointConfig::default(),
}
}
#[must_use]
pub fn memory() -> Self {
Self {
storage: Storage::Memory,
buffer_pool_size: 64,
wal_sync: false,
memory_flush_on_write: true,
checkpoint: CheckpointConfig {
enabled: false,
..CheckpointConfig::default()
},
}
}
#[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::File { dir } => Some(dir.join("journal.wal")),
Storage::Memory => None,
}
}
}