use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StorageConfig {
pub db_path: PathBuf,
pub cache_size: usize,
pub compression: bool,
pub max_open_files: i32,
pub write_buffer_size: usize,
pub max_write_buffer_number: i32,
pub target_file_size_base: u64,
pub enable_statistics: bool,
pub snapshot_retention: u64,
pub enable_wal: bool,
}
impl Default for StorageConfig {
fn default() -> Self {
Self {
db_path: PathBuf::from("./data/tenzro-db"),
cache_size: 512 * 1024 * 1024, compression: true,
max_open_files: 1000,
write_buffer_size: 64 * 1024 * 1024, max_write_buffer_number: 3,
target_file_size_base: 64 * 1024 * 1024, enable_statistics: false,
snapshot_retention: 100,
enable_wal: true,
}
}
}
impl StorageConfig {
pub fn new(db_path: PathBuf) -> Self {
Self {
db_path,
..Default::default()
}
}
pub fn with_cache_size(mut self, size: usize) -> Self {
self.cache_size = size;
self
}
pub fn with_compression(mut self, enabled: bool) -> Self {
self.compression = enabled;
self
}
pub fn with_max_open_files(mut self, max: i32) -> Self {
self.max_open_files = max;
self
}
pub fn with_write_buffer_size(mut self, size: usize) -> Self {
self.write_buffer_size = size;
self
}
pub fn with_snapshot_retention(mut self, count: u64) -> Self {
self.snapshot_retention = count;
self
}
pub fn with_wal(mut self, enabled: bool) -> Self {
self.enable_wal = enabled;
self
}
}