omendb_core/
config.rs

1//! Configuration for `OmenDB` storage
2//!
3//! Provides configuration options for the underlying storage engine.
4
5use serde::{Deserialize, Serialize};
6
7/// Configuration for `OmenDB` storage
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct StorageConfig {
10    /// WAL sync policy (fsync behavior)
11    /// Default: false (`SyncPolicy::None` - for performance)
12    pub sync_writes: bool,
13
14    /// Memtable capacity in bytes
15    /// Default: 128MB
16    pub memtable_capacity: usize,
17
18    /// Block cache capacity in bytes
19    /// Default: 128MB
20    pub block_cache_capacity: usize,
21
22    /// Enable background compaction
23    /// Default: true
24    pub background_compaction: bool,
25}
26
27impl Default for StorageConfig {
28    fn default() -> Self {
29        Self {
30            sync_writes: false, // Default to performance for vector graphs (derived data)
31            memtable_capacity: 128 * 1024 * 1024,
32            block_cache_capacity: 128 * 1024 * 1024,
33            background_compaction: true,
34        }
35    }
36}
37
38impl StorageConfig {
39    /// Create a new config builder
40    #[must_use]
41    pub fn builder() -> StorageConfigBuilder {
42        StorageConfigBuilder::default()
43    }
44}
45
46/// Builder for `StorageConfig`
47#[derive(Debug, Default)]
48pub struct StorageConfigBuilder {
49    sync_writes: Option<bool>,
50    memtable_capacity: Option<usize>,
51    block_cache_capacity: Option<usize>,
52    background_compaction: Option<bool>,
53}
54
55impl StorageConfigBuilder {
56    /// Set sync writes policy
57    #[must_use]
58    pub fn sync_writes(mut self, enabled: bool) -> Self {
59        self.sync_writes = Some(enabled);
60        self
61    }
62
63    /// Set memtable capacity
64    #[must_use]
65    pub fn memtable_capacity(mut self, capacity: usize) -> Self {
66        self.memtable_capacity = Some(capacity);
67        self
68    }
69
70    /// Set block cache capacity
71    #[must_use]
72    pub fn block_cache_capacity(mut self, capacity: usize) -> Self {
73        self.block_cache_capacity = Some(capacity);
74        self
75    }
76
77    /// Enable/disable background compaction
78    #[must_use]
79    pub fn background_compaction(mut self, enabled: bool) -> Self {
80        self.background_compaction = Some(enabled);
81        self
82    }
83
84    /// Build configuration
85    #[must_use]
86    pub fn build(self) -> StorageConfig {
87        let defaults = StorageConfig::default();
88
89        StorageConfig {
90            sync_writes: self.sync_writes.unwrap_or(defaults.sync_writes),
91            memtable_capacity: self.memtable_capacity.unwrap_or(defaults.memtable_capacity),
92            block_cache_capacity: self
93                .block_cache_capacity
94                .unwrap_or(defaults.block_cache_capacity),
95            background_compaction: self
96                .background_compaction
97                .unwrap_or(defaults.background_compaction),
98        }
99    }
100}