1#[derive(Clone, Debug)]
3pub struct DatabaseConfig {
4 pub buffer_pool_size: usize,
6 pub read_pool_ratio: f64,
8 pub max_threads: usize,
10 pub enable_compression: bool,
12 pub checkpoint_threshold: u64,
14 pub jit_enabled: bool,
16 pub jit_threshold: u64,
18 pub jit_cache_capacity: usize,
20}
21
22impl Default for DatabaseConfig {
23 fn default() -> Self {
24 Self {
25 buffer_pool_size: 256 * 1024 * 1024, 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, 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}