1#[derive(Clone, Debug, Default)]
9pub struct Config {
10 pub wal: chunked_wal::Config,
12
13 pub log_cache_max_items: Option<usize>,
15
16 pub log_cache_capacity: Option<usize>,
18}
19
20impl Config {
21 pub fn new(dir: impl ToString) -> Self {
24 Self {
25 wal: chunked_wal::Config::new(dir),
26 ..Default::default()
27 }
28 }
29
30 pub fn log_cache_max_items(&self) -> usize {
32 self.log_cache_max_items.unwrap_or(100_000)
33 }
34
35 pub fn log_cache_capacity(&self) -> usize {
37 self.log_cache_capacity.unwrap_or(1024 * 1024 * 1024)
38 }
39}
40
41#[cfg(test)]
42mod tests {
43 use super::Config;
44
45 #[test]
46 fn test_explicit_config_embeds_wal_config() {
47 let config = Config {
48 wal: crate::chunked_wal::Config {
49 dir: "raft-log-dir".to_string(),
50 read_buffer_size: Some(13),
51 chunk_max_records: Some(17),
52 chunk_max_size: Some(19),
53 truncate_incomplete_record: None,
54 flush_batch_wait: None,
55 flush_batch_max_items: None,
56 },
57 log_cache_max_items: Some(7),
58 log_cache_capacity: Some(11),
59 };
60
61 assert_eq!("raft-log-dir", config.wal.dir);
62 assert_eq!(Some(13), config.wal.read_buffer_size);
63 assert_eq!(Some(17), config.wal.chunk_max_records);
64 assert_eq!(Some(19), config.wal.chunk_max_size);
65 assert_eq!(None, config.wal.truncate_incomplete_record);
66 assert_eq!(None, config.wal.flush_batch_wait);
67 assert_eq!(None, config.wal.flush_batch_max_items);
68 assert_eq!(7, config.log_cache_max_items());
69 assert_eq!(11, config.log_cache_capacity());
70 }
71}