1#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
16pub enum DurabilityPolicy {
17 SyncOnCheckpoint,
24 #[default]
27 SyncOnEveryWrite,
28}
29
30#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
31pub enum RecoveryMode {
32 Strict,
33 #[default]
37 AutoRepairTornTail,
38 DoctorRepairTornTail,
40}
41
42#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
43pub enum DurableCompression {
44 #[default]
45 Zstd,
46}
47
48pub const DEFAULT_MAX_WAL_REPLAY_ENTRIES: usize = 1_000_000;
49pub const DEFAULT_MAX_WAL_REPLAY_BYTES: u64 = 1024 * 1024 * 1024;
50pub const DEFAULT_MAX_BRANCH_SEALED_WAL_INTERVALS: usize = 256;
51pub const DEFAULT_MAX_WAL_QUARANTINE_BYTES: u64 = DEFAULT_MAX_WAL_REPLAY_BYTES;
52pub const DEFAULT_MAX_WAL_RECORD_BYTES: usize = 16 * 1024 * 1024;
53pub const DEFAULT_MAX_WAL_BATCH_OPERATIONS: usize = 100_000;
54pub const DEFAULT_MAX_CHECKPOINT_ENCODED_BYTES: u64 = 1024 * 1024 * 1024 * 1024;
55pub const DEFAULT_MAX_CHECKPOINT_DECODED_BYTES: u64 = 4 * 1024 * 1024 * 1024 * 1024;
56pub const DEFAULT_SEGMENT_CACHE_CAPACITY_BYTES: u64 = 256 * 1024 * 1024;
57pub const DEFAULT_MAX_GRAPH_MANIFEST_OPEN_BYTES: u64 = 64 * 1024 * 1024;
63pub const DEFAULT_AUTO_MATERIALIZE_CHECKPOINT_BYTES: u64 = 64 * 1024 * 1024;
64pub const DEFAULT_MAX_OUT_OF_CORE_DELTA_BYTES: u64 = 256 * 1024 * 1024;
65
66#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
67pub enum StorageResidencyMode {
68 #[default]
69 Auto,
70 Materialized,
71 OutOfCore,
72}
73
74#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
80pub enum RelationalIndexMode {
81 #[default]
83 Materialized,
84 Shadow,
86 DemandPaged,
88 Authoritative,
94}
95
96impl RelationalIndexMode {
97 pub const fn publishes_persistent_indexes(self) -> bool {
98 !matches!(self, Self::Materialized)
99 }
100
101 pub const fn serves_demand_paged_reads(self) -> bool {
102 matches!(self, Self::DemandPaged | Self::Authoritative)
103 }
104
105 pub const fn requires_authoritative_indexes(self) -> bool {
106 matches!(self, Self::Authoritative)
107 }
108}
109
110#[derive(Debug, Clone, Copy, PartialEq, Eq)]
111pub struct WalReplayConfig {
112 pub max_open_files: usize,
115 pub strict_capacity_limit: bool,
117 pub recovery_mode: RecoveryMode,
118 pub max_entries: Option<usize>,
119 pub max_bytes: Option<u64>,
120 pub max_branch_sealed_wal_intervals: usize,
124 pub max_quarantine_bytes: u64,
128 pub max_record_bytes: Option<usize>,
129 pub max_batch_operations: Option<usize>,
130 pub max_checkpoint_encoded_bytes: Option<u64>,
131 pub max_checkpoint_decoded_bytes: Option<u64>,
132 pub segment_cache_capacity_bytes: u64,
133 pub max_graph_manifest_open_bytes: u64,
134 pub residency_mode: StorageResidencyMode,
135 pub auto_materialize_checkpoint_bytes: u64,
136 pub max_out_of_core_delta_bytes: Option<u64>,
137 pub graph_columnar_shadow_checkpoint: bool,
141 pub relational_index_mode: RelationalIndexMode,
143}
144
145impl Default for WalReplayConfig {
146 fn default() -> Self {
147 Self {
148 max_open_files: crate::file_descriptors::DEFAULT_MAX_OPEN_FILES,
149 strict_capacity_limit: false,
150 recovery_mode: RecoveryMode::default(),
151 max_entries: Some(DEFAULT_MAX_WAL_REPLAY_ENTRIES),
152 max_bytes: Some(DEFAULT_MAX_WAL_REPLAY_BYTES),
153 max_branch_sealed_wal_intervals: DEFAULT_MAX_BRANCH_SEALED_WAL_INTERVALS,
154 max_quarantine_bytes: DEFAULT_MAX_WAL_QUARANTINE_BYTES,
155 max_record_bytes: Some(DEFAULT_MAX_WAL_RECORD_BYTES),
156 max_batch_operations: Some(DEFAULT_MAX_WAL_BATCH_OPERATIONS),
157 max_checkpoint_encoded_bytes: Some(DEFAULT_MAX_CHECKPOINT_ENCODED_BYTES),
158 max_checkpoint_decoded_bytes: Some(DEFAULT_MAX_CHECKPOINT_DECODED_BYTES),
159 segment_cache_capacity_bytes: DEFAULT_SEGMENT_CACHE_CAPACITY_BYTES,
160 max_graph_manifest_open_bytes: DEFAULT_MAX_GRAPH_MANIFEST_OPEN_BYTES,
161 residency_mode: StorageResidencyMode::Auto,
162 auto_materialize_checkpoint_bytes: DEFAULT_AUTO_MATERIALIZE_CHECKPOINT_BYTES,
163 max_out_of_core_delta_bytes: Some(DEFAULT_MAX_OUT_OF_CORE_DELTA_BYTES),
164 graph_columnar_shadow_checkpoint: false,
165 relational_index_mode: RelationalIndexMode::default(),
166 }
167 }
168}
169
170#[cfg(test)]
171mod tests {
172 use super::*;
173
174 #[test]
175 fn defaults_are_bounded_and_recoverable() {
176 assert_eq!(
177 DurabilityPolicy::default(),
178 DurabilityPolicy::SyncOnEveryWrite
179 );
180 assert_eq!(RecoveryMode::default(), RecoveryMode::AutoRepairTornTail);
181 assert_eq!(DurableCompression::default(), DurableCompression::Zstd);
182 assert_eq!(
183 RelationalIndexMode::default(),
184 RelationalIndexMode::Materialized
185 );
186 assert!(!RelationalIndexMode::Materialized.publishes_persistent_indexes());
187 assert!(!RelationalIndexMode::Materialized.serves_demand_paged_reads());
188 assert!(RelationalIndexMode::Shadow.publishes_persistent_indexes());
189 assert!(!RelationalIndexMode::Shadow.serves_demand_paged_reads());
190 assert!(RelationalIndexMode::DemandPaged.publishes_persistent_indexes());
191 assert!(RelationalIndexMode::DemandPaged.serves_demand_paged_reads());
192 assert!(!RelationalIndexMode::DemandPaged.requires_authoritative_indexes());
193 assert!(RelationalIndexMode::Authoritative.publishes_persistent_indexes());
194 assert!(RelationalIndexMode::Authoritative.serves_demand_paged_reads());
195 assert!(RelationalIndexMode::Authoritative.requires_authoritative_indexes());
196 let replay = WalReplayConfig::default();
197 assert_eq!(replay.max_entries, Some(DEFAULT_MAX_WAL_REPLAY_ENTRIES));
198 assert_eq!(replay.max_bytes, Some(DEFAULT_MAX_WAL_REPLAY_BYTES));
199 assert_eq!(
200 replay.max_quarantine_bytes,
201 DEFAULT_MAX_WAL_QUARANTINE_BYTES
202 );
203 assert_eq!(replay.max_record_bytes, Some(DEFAULT_MAX_WAL_RECORD_BYTES));
204 assert_eq!(
205 replay.max_batch_operations,
206 Some(DEFAULT_MAX_WAL_BATCH_OPERATIONS)
207 );
208 assert_eq!(
209 replay.max_out_of_core_delta_bytes,
210 Some(DEFAULT_MAX_OUT_OF_CORE_DELTA_BYTES)
211 );
212 assert_eq!(
213 replay.max_graph_manifest_open_bytes,
214 DEFAULT_MAX_GRAPH_MANIFEST_OPEN_BYTES
215 );
216 }
217}