diff --git a/src/config/mod.rs b/src/config/mod.rs index 9c9e0dc3..8ca8ee6b 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -161,6 +161,8 @@ pub struct Config { pub rocksdb_bottommost_compression_level: i32, #[serde(default)] pub rocksdb_bottommost_compression: bool, + #[serde(default = "default_rocksdb_recovery_mode")] + pub rocksdb_recovery_mode: u32, pub emergency_password: Option, @@ -451,6 +453,8 @@ impl fmt::Display for Config { "RocksDB Bottommost Level Compression", &self.rocksdb_bottommost_compression.to_string(), ), + #[cfg(feature = "rocksdb")] + ("RocksDB Recovery mode", &self.rocksdb_recovery_mode.to_string()), ("Prevent Media Downloads From", { let mut lst = vec![]; for domain in &self.prevent_media_downloads_from { @@ -572,6 +576,8 @@ fn default_presence_idle_timeout_s() -> u64 { 5 * 60 } fn default_presence_offline_timeout_s() -> u64 { 30 * 60 } +fn default_rocksdb_recovery_mode() -> u32 { 1 } + fn default_rocksdb_log_level() -> String { "error".to_owned() } fn default_rocksdb_log_time_to_roll() -> usize { 0 } diff --git a/src/database/abstraction/rocksdb.rs b/src/database/abstraction/rocksdb.rs index 33d14371..d5c8ad9f 100644 --- a/src/database/abstraction/rocksdb.rs +++ b/src/database/abstraction/rocksdb.rs @@ -121,7 +121,13 @@ fn db_options( // Unclean shutdowns of a Matrix homeserver are likely to be fine when // recovered in this manner as it's likely any lost information will be // restored via federation. - db_opts.set_wal_recovery_mode(rust_rocksdb::DBRecoveryMode::TolerateCorruptedTailRecords); + db_opts.set_wal_recovery_mode(match config.rocksdb_recovery_mode { + 0 => rust_rocksdb::DBRecoveryMode::AbsoluteConsistency, + 1 => rust_rocksdb::DBRecoveryMode::TolerateCorruptedTailRecords, + 2 => rust_rocksdb::DBRecoveryMode::PointInTime, + 3 => rust_rocksdb::DBRecoveryMode::SkipAnyCorruptedRecord, + 4_u8..=u8::MAX => unimplemented!(), + }); db_opts.set_block_based_table_factory(&block_based_options); db_opts.set_env(env);