1use std::thread;
2use std::time::Duration;
3
4#[derive(Clone, Debug)]
6pub struct StoreConfig {
7 pub data_dir: String,
9 pub max_segment_size: u64,
11 pub compaction_interval: Duration,
13 pub fsync_interval: Duration,
15 pub emit_snapshot_after_compaction: bool,
17 pub worker_threads: usize,
19}
20
21impl Default for StoreConfig {
22 fn default() -> Self {
23 let default_workers = thread::available_parallelism()
24 .map(|n| n.get())
25 .unwrap_or(2)
26 .max(1);
27 Self {
28 data_dir: ".hightower".to_string(),
29 max_segment_size: 64 * 1024 * 1024,
30 compaction_interval: Duration::from_secs(60),
31 fsync_interval: Duration::from_millis(25),
32 emit_snapshot_after_compaction: true,
33 worker_threads: default_workers,
34 }
35 }
36}
37
38#[cfg(test)]
39mod tests {
40 use super::*;
41
42 #[test]
43 fn default_values_are_reasonable() {
44 let cfg = StoreConfig::default();
45 assert_eq!(cfg.data_dir, ".hightower");
46 assert!(cfg.max_segment_size >= 4 * 1024 * 1024);
47 assert!(cfg.compaction_interval >= Duration::from_secs(1));
48 assert!(cfg.fsync_interval <= Duration::from_millis(100));
49 assert!(cfg.emit_snapshot_after_compaction);
50 assert!(cfg.worker_threads >= 1);
51 }
52}