#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum DurabilityPolicy {
SyncOnCheckpoint,
#[default]
SyncOnEveryWrite,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum RecoveryMode {
#[default]
Strict,
AutoRepairTornTail,
DoctorRepairTornTail,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum DurableCompression {
#[default]
Zstd,
}
pub const DEFAULT_MAX_WAL_REPLAY_ENTRIES: usize = 1_000_000;
pub const DEFAULT_MAX_WAL_REPLAY_BYTES: u64 = 1024 * 1024 * 1024;
pub const DEFAULT_MAX_BRANCH_SEALED_WAL_INTERVALS: usize = 256;
pub const DEFAULT_MAX_WAL_QUARANTINE_BYTES: u64 = DEFAULT_MAX_WAL_REPLAY_BYTES;
pub const DEFAULT_MAX_WAL_RECORD_BYTES: usize = 16 * 1024 * 1024;
pub const DEFAULT_MAX_WAL_BATCH_OPERATIONS: usize = 100_000;
pub const DEFAULT_MAX_CHECKPOINT_ENCODED_BYTES: u64 = 1024 * 1024 * 1024 * 1024;
pub const DEFAULT_MAX_CHECKPOINT_DECODED_BYTES: u64 = 4 * 1024 * 1024 * 1024 * 1024;
pub const DEFAULT_SEGMENT_CACHE_CAPACITY_BYTES: u64 = 256 * 1024 * 1024;
pub const DEFAULT_MAX_GRAPH_MANIFEST_OPEN_BYTES: u64 = 64 * 1024 * 1024;
pub const DEFAULT_AUTO_MATERIALIZE_CHECKPOINT_BYTES: u64 = 64 * 1024 * 1024;
pub const DEFAULT_MAX_OUT_OF_CORE_DELTA_BYTES: u64 = 256 * 1024 * 1024;
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum StorageResidencyMode {
#[default]
Auto,
Materialized,
OutOfCore,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum RelationalIndexMode {
#[default]
Materialized,
Shadow,
DemandPaged,
Authoritative,
}
impl RelationalIndexMode {
pub const fn publishes_persistent_indexes(self) -> bool {
!matches!(self, Self::Materialized)
}
pub const fn serves_demand_paged_reads(self) -> bool {
matches!(self, Self::DemandPaged | Self::Authoritative)
}
pub const fn requires_authoritative_indexes(self) -> bool {
matches!(self, Self::Authoritative)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct WalReplayConfig {
pub max_open_files: usize,
pub strict_capacity_limit: bool,
pub recovery_mode: RecoveryMode,
pub max_entries: Option<usize>,
pub max_bytes: Option<u64>,
pub max_branch_sealed_wal_intervals: usize,
pub max_quarantine_bytes: u64,
pub max_record_bytes: Option<usize>,
pub max_batch_operations: Option<usize>,
pub max_checkpoint_encoded_bytes: Option<u64>,
pub max_checkpoint_decoded_bytes: Option<u64>,
pub segment_cache_capacity_bytes: u64,
pub max_graph_manifest_open_bytes: u64,
pub residency_mode: StorageResidencyMode,
pub auto_materialize_checkpoint_bytes: u64,
pub max_out_of_core_delta_bytes: Option<u64>,
pub graph_columnar_shadow_checkpoint: bool,
pub relational_index_mode: RelationalIndexMode,
}
impl Default for WalReplayConfig {
fn default() -> Self {
Self {
max_open_files: crate::file_descriptors::DEFAULT_MAX_OPEN_FILES,
strict_capacity_limit: false,
recovery_mode: RecoveryMode::default(),
max_entries: Some(DEFAULT_MAX_WAL_REPLAY_ENTRIES),
max_bytes: Some(DEFAULT_MAX_WAL_REPLAY_BYTES),
max_branch_sealed_wal_intervals: DEFAULT_MAX_BRANCH_SEALED_WAL_INTERVALS,
max_quarantine_bytes: DEFAULT_MAX_WAL_QUARANTINE_BYTES,
max_record_bytes: Some(DEFAULT_MAX_WAL_RECORD_BYTES),
max_batch_operations: Some(DEFAULT_MAX_WAL_BATCH_OPERATIONS),
max_checkpoint_encoded_bytes: Some(DEFAULT_MAX_CHECKPOINT_ENCODED_BYTES),
max_checkpoint_decoded_bytes: Some(DEFAULT_MAX_CHECKPOINT_DECODED_BYTES),
segment_cache_capacity_bytes: DEFAULT_SEGMENT_CACHE_CAPACITY_BYTES,
max_graph_manifest_open_bytes: DEFAULT_MAX_GRAPH_MANIFEST_OPEN_BYTES,
residency_mode: StorageResidencyMode::Auto,
auto_materialize_checkpoint_bytes: DEFAULT_AUTO_MATERIALIZE_CHECKPOINT_BYTES,
max_out_of_core_delta_bytes: Some(DEFAULT_MAX_OUT_OF_CORE_DELTA_BYTES),
graph_columnar_shadow_checkpoint: false,
relational_index_mode: RelationalIndexMode::default(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn defaults_are_bounded_and_recoverable() {
assert_eq!(
DurabilityPolicy::default(),
DurabilityPolicy::SyncOnEveryWrite
);
assert_eq!(RecoveryMode::default(), RecoveryMode::Strict);
assert_eq!(DurableCompression::default(), DurableCompression::Zstd);
assert_eq!(
RelationalIndexMode::default(),
RelationalIndexMode::Materialized
);
assert!(!RelationalIndexMode::Materialized.publishes_persistent_indexes());
assert!(!RelationalIndexMode::Materialized.serves_demand_paged_reads());
assert!(RelationalIndexMode::Shadow.publishes_persistent_indexes());
assert!(!RelationalIndexMode::Shadow.serves_demand_paged_reads());
assert!(RelationalIndexMode::DemandPaged.publishes_persistent_indexes());
assert!(RelationalIndexMode::DemandPaged.serves_demand_paged_reads());
assert!(!RelationalIndexMode::DemandPaged.requires_authoritative_indexes());
assert!(RelationalIndexMode::Authoritative.publishes_persistent_indexes());
assert!(RelationalIndexMode::Authoritative.serves_demand_paged_reads());
assert!(RelationalIndexMode::Authoritative.requires_authoritative_indexes());
let replay = WalReplayConfig::default();
assert_eq!(replay.max_entries, Some(DEFAULT_MAX_WAL_REPLAY_ENTRIES));
assert_eq!(replay.max_bytes, Some(DEFAULT_MAX_WAL_REPLAY_BYTES));
assert_eq!(
replay.max_quarantine_bytes,
DEFAULT_MAX_WAL_QUARANTINE_BYTES
);
assert_eq!(replay.max_record_bytes, Some(DEFAULT_MAX_WAL_RECORD_BYTES));
assert_eq!(
replay.max_batch_operations,
Some(DEFAULT_MAX_WAL_BATCH_OPERATIONS)
);
assert_eq!(
replay.max_out_of_core_delta_bytes,
Some(DEFAULT_MAX_OUT_OF_CORE_DELTA_BYTES)
);
assert_eq!(
replay.max_graph_manifest_open_bytes,
DEFAULT_MAX_GRAPH_MANIFEST_OPEN_BYTES
);
}
}