Skip to main content

kyu_common/
config.rs

1/// Configuration for a KyuGraph database instance.
2#[derive(Clone, Debug)]
3pub struct DatabaseConfig {
4    /// Total buffer pool size in bytes. Default: 256 MB.
5    pub buffer_pool_size: usize,
6    /// Fraction of buffer pool allocated to the read pool. Default: 0.7 (70%).
7    pub read_pool_ratio: f64,
8    /// Maximum number of worker threads. Default: number of CPUs.
9    pub max_threads: usize,
10    /// Enable column compression. Default: true.
11    pub enable_compression: bool,
12    /// WAL size threshold in bytes before triggering checkpoint. Default: 256 MB.
13    pub checkpoint_threshold: u64,
14    /// Enable JIT compilation for hot expressions. Default: true.
15    pub jit_enabled: bool,
16    /// Row count threshold before JIT compilation triggers. Default: 100,000.
17    pub jit_threshold: u64,
18    /// Maximum number of cached compiled expressions. Default: 1024.
19    pub jit_cache_capacity: usize,
20}
21
22impl Default for DatabaseConfig {
23    fn default() -> Self {
24        Self {
25            buffer_pool_size: 256 * 1024 * 1024, // 256 MB
26            read_pool_ratio: 0.7,
27            max_threads: std::thread::available_parallelism()
28                .map(|n| n.get())
29                .unwrap_or(4),
30            enable_compression: true,
31            checkpoint_threshold: 256 * 1024 * 1024, // 256 MB
32            jit_enabled: true,
33            jit_threshold: 100_000,
34            jit_cache_capacity: 1024,
35        }
36    }
37}
38
39#[cfg(test)]
40mod tests {
41    use super::*;
42
43    #[test]
44    fn default_values() {
45        let config = DatabaseConfig::default();
46        assert_eq!(config.buffer_pool_size, 256 * 1024 * 1024);
47        assert!((config.read_pool_ratio - 0.7).abs() < f64::EPSILON);
48        assert!(config.max_threads >= 1);
49        assert!(config.enable_compression);
50        assert_eq!(config.checkpoint_threshold, 256 * 1024 * 1024);
51    }
52
53    #[test]
54    fn custom_config() {
55        let config = DatabaseConfig {
56            buffer_pool_size: 1024 * 1024 * 1024,
57            read_pool_ratio: 0.8,
58            max_threads: 16,
59            enable_compression: false,
60            checkpoint_threshold: 512 * 1024 * 1024,
61            jit_enabled: false,
62            jit_threshold: 0,
63            jit_cache_capacity: 512,
64        };
65        assert_eq!(config.buffer_pool_size, 1024 * 1024 * 1024);
66        assert!(!config.enable_compression);
67        assert!(!config.jit_enabled);
68    }
69}