1use std::path::PathBuf;
4
5#[derive(Debug, Clone)]
7pub struct Config {
8 pub path: Option<PathBuf>,
10
11 pub memory_limit: Option<usize>,
13
14 pub spill_path: Option<PathBuf>,
16
17 pub threads: usize,
19
20 pub wal_enabled: bool,
22
23 pub wal_flush_interval_ms: u64,
25
26 pub backward_edges: bool,
28
29 pub query_logging: bool,
31}
32
33impl Default for Config {
34 fn default() -> Self {
35 Self {
36 path: None,
37 memory_limit: None,
38 spill_path: None,
39 threads: num_cpus::get(),
40 wal_enabled: true,
41 wal_flush_interval_ms: 100,
42 backward_edges: true,
43 query_logging: false,
44 }
45 }
46}
47
48impl Config {
49 #[must_use]
51 pub fn in_memory() -> Self {
52 Self {
53 path: None,
54 wal_enabled: false,
55 ..Default::default()
56 }
57 }
58
59 #[must_use]
61 pub fn persistent(path: impl Into<PathBuf>) -> Self {
62 Self {
63 path: Some(path.into()),
64 wal_enabled: true,
65 ..Default::default()
66 }
67 }
68
69 #[must_use]
71 pub fn with_memory_limit(mut self, limit: usize) -> Self {
72 self.memory_limit = Some(limit);
73 self
74 }
75
76 #[must_use]
78 pub fn with_threads(mut self, threads: usize) -> Self {
79 self.threads = threads;
80 self
81 }
82
83 #[must_use]
85 pub fn without_backward_edges(mut self) -> Self {
86 self.backward_edges = false;
87 self
88 }
89
90 #[must_use]
92 pub fn with_query_logging(mut self) -> Self {
93 self.query_logging = true;
94 self
95 }
96
97 #[must_use]
99 pub fn with_memory_fraction(mut self, fraction: f64) -> Self {
100 use grafeo_common::memory::buffer::BufferManagerConfig;
101 let system_memory = BufferManagerConfig::detect_system_memory();
102 self.memory_limit = Some((system_memory as f64 * fraction) as usize);
103 self
104 }
105
106 #[must_use]
108 pub fn with_spill_path(mut self, path: impl Into<PathBuf>) -> Self {
109 self.spill_path = Some(path.into());
110 self
111 }
112}
113
114mod num_cpus {
116 pub fn get() -> usize {
117 std::thread::available_parallelism()
118 .map(|n| n.get())
119 .unwrap_or(4)
120 }
121}