azoth_core/config/
canonical.rs1use serde::{Deserialize, Serialize};
2use std::path::PathBuf;
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct ReadPoolConfig {
10 #[serde(default)]
12 pub enabled: bool,
13
14 #[serde(default = "default_pool_size")]
19 pub pool_size: usize,
20
21 #[serde(default = "default_acquire_timeout")]
25 pub acquire_timeout_ms: u64,
26}
27
28impl Default for ReadPoolConfig {
29 fn default() -> Self {
30 Self {
31 enabled: false,
32 pool_size: default_pool_size(),
33 acquire_timeout_ms: default_acquire_timeout(),
34 }
35 }
36}
37
38impl ReadPoolConfig {
39 pub fn enabled(pool_size: usize) -> Self {
41 Self {
42 enabled: true,
43 pool_size,
44 acquire_timeout_ms: default_acquire_timeout(),
45 }
46 }
47
48 pub fn with_timeout(mut self, timeout_ms: u64) -> Self {
50 self.acquire_timeout_ms = timeout_ms;
51 self
52 }
53}
54
55fn default_pool_size() -> usize {
56 4
57}
58
59fn default_acquire_timeout() -> u64 {
60 5000
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
65pub struct CanonicalConfig {
66 pub path: PathBuf,
68
69 #[serde(default = "default_map_size")]
72 pub map_size: usize,
73
74 #[serde(default)]
76 pub sync_mode: SyncMode,
77
78 #[serde(default = "default_stripe_count")]
81 pub stripe_count: usize,
82
83 #[serde(default = "default_max_readers")]
86 pub max_readers: u32,
87
88 #[serde(default = "default_true")]
93 pub preflight_read_only: bool,
94
95 #[serde(default = "default_chunk_size")]
100 pub state_iter_chunk_size: usize,
101
102 #[serde(default = "default_true")]
107 pub preflight_cache_enabled: bool,
108
109 #[serde(default = "default_preflight_cache_size")]
114 pub preflight_cache_size: usize,
115
116 #[serde(default = "default_preflight_cache_ttl")]
120 pub preflight_cache_ttl_secs: u64,
121
122 #[serde(default)]
127 pub read_pool: ReadPoolConfig,
128
129 #[serde(default = "default_lock_timeout")]
135 pub lock_timeout_ms: u64,
136
137 #[serde(default = "default_event_max_size")]
139 pub event_max_size_bytes: usize,
140
141 #[serde(default = "default_event_batch_max_bytes")]
143 pub event_batch_max_bytes: usize,
144}
145
146#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
147pub enum SyncMode {
148 Full,
154
155 #[default]
162 NoMetaSync,
163
164 NoSync,
171}
172
173fn default_map_size() -> usize {
174 10 * 1024 * 1024 * 1024 }
176
177fn default_stripe_count() -> usize {
178 256
179}
180
181fn default_max_readers() -> u32 {
182 126
183}
184
185fn default_true() -> bool {
186 true
187}
188
189fn default_chunk_size() -> usize {
190 1000
191}
192
193fn default_preflight_cache_size() -> usize {
194 10_000
195}
196
197fn default_preflight_cache_ttl() -> u64 {
198 60
199}
200
201fn default_lock_timeout() -> u64 {
202 5000
203}
204
205fn default_event_max_size() -> usize {
206 4 * 1024 * 1024
207}
208
209fn default_event_batch_max_bytes() -> usize {
210 64 * 1024 * 1024
211}
212
213impl CanonicalConfig {
214 pub fn new(path: PathBuf) -> Self {
215 Self {
216 path,
217 map_size: default_map_size(),
218 sync_mode: SyncMode::default(),
219 stripe_count: default_stripe_count(),
220 max_readers: default_max_readers(),
221 preflight_read_only: default_true(),
222 state_iter_chunk_size: default_chunk_size(),
223 preflight_cache_enabled: default_true(),
224 preflight_cache_size: default_preflight_cache_size(),
225 preflight_cache_ttl_secs: default_preflight_cache_ttl(),
226 read_pool: ReadPoolConfig::default(),
227 lock_timeout_ms: default_lock_timeout(),
228 event_max_size_bytes: default_event_max_size(),
229 event_batch_max_bytes: default_event_batch_max_bytes(),
230 }
231 }
232
233 pub fn with_map_size(mut self, map_size: usize) -> Self {
234 self.map_size = map_size;
235 self
236 }
237
238 pub fn with_sync_mode(mut self, sync_mode: SyncMode) -> Self {
239 self.sync_mode = sync_mode;
240 self
241 }
242
243 pub fn with_stripe_count(mut self, stripe_count: usize) -> Self {
244 self.stripe_count = stripe_count;
245 self
246 }
247
248 pub fn with_preflight_cache(mut self, enabled: bool) -> Self {
249 self.preflight_cache_enabled = enabled;
250 self
251 }
252
253 pub fn with_preflight_cache_size(mut self, size: usize) -> Self {
254 self.preflight_cache_size = size;
255 self
256 }
257
258 pub fn with_preflight_cache_ttl(mut self, ttl_secs: u64) -> Self {
259 self.preflight_cache_ttl_secs = ttl_secs;
260 self
261 }
262
263 pub fn with_read_pool(mut self, config: ReadPoolConfig) -> Self {
265 self.read_pool = config;
266 self
267 }
268
269 pub fn with_read_pool_size(mut self, pool_size: usize) -> Self {
271 self.read_pool = ReadPoolConfig::enabled(pool_size);
272 self
273 }
274
275 pub fn with_lock_timeout(mut self, timeout_ms: u64) -> Self {
280 self.lock_timeout_ms = timeout_ms;
281 self
282 }
283
284 pub fn with_event_max_size(mut self, size_bytes: usize) -> Self {
286 self.event_max_size_bytes = size_bytes;
287 self
288 }
289
290 pub fn with_event_batch_max_bytes(mut self, size_bytes: usize) -> Self {
292 self.event_batch_max_bytes = size_bytes;
293 self
294 }
295}