lora_wal/config.rs
1use std::path::PathBuf;
2
3/// Durability mode for committed transactions.
4///
5/// Commits write WAL bytes to the OS before returning, then a background
6/// flusher, explicit `force_fsync`, checkpoint, `Database::sync`, or clean
7/// drop creates the storage durability boundary.
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum SyncMode {
10 /// Write commit bytes to the OS immediately, but defer `fsync` until an
11 /// explicit durability boundary or the background flusher interval.
12 /// Background fsync failures poison the WAL through `Wal::bg_failure`.
13 GroupSync { interval_ms: u32 },
14}
15
16impl Default for SyncMode {
17 fn default() -> Self {
18 Self::GroupSync { interval_ms: 50 }
19 }
20}
21
22/// Configuration for opening a [`Wal`](crate::wal::Wal).
23///
24/// `Disabled` is the zero-overhead variant `lora-database` falls back to
25/// when the operator has not configured a WAL directory; it does not
26/// install a recorder or open any files.
27#[derive(Debug, Clone, Default)]
28pub enum WalConfig {
29 #[default]
30 Disabled,
31 Enabled {
32 dir: PathBuf,
33 sync_mode: SyncMode,
34 /// Target size of an active segment before rotation. Rotation
35 /// only happens at a `TxBegin` boundary so a transaction never
36 /// spans segments.
37 segment_target_bytes: u64,
38 },
39}
40
41impl WalConfig {
42 /// Quick constructor for the default `GroupSync` mode and an 8 MiB
43 /// segment target.
44 pub fn enabled(dir: impl Into<PathBuf>) -> Self {
45 Self::Enabled {
46 dir: dir.into(),
47 sync_mode: SyncMode::default(),
48 segment_target_bytes: 8 * 1024 * 1024,
49 }
50 }
51}