add conf items for rocksdb repair and read-only modes.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-03-25 16:51:55 -07:00 committed by June
parent 5f11d68616
commit fe91ce0601
2 changed files with 31 additions and 13 deletions

View file

@ -207,6 +207,10 @@ pub struct Config {
pub rocksdb_bottommost_compression: bool, pub rocksdb_bottommost_compression: bool,
#[serde(default = "default_rocksdb_recovery_mode")] #[serde(default = "default_rocksdb_recovery_mode")]
pub rocksdb_recovery_mode: u8, pub rocksdb_recovery_mode: u8,
#[serde(default)]
pub rocksdb_repair: bool,
#[serde(default)]
pub rocksdb_read_only: bool,
pub emergency_password: Option<String>, pub emergency_password: Option<String>,
@ -629,6 +633,8 @@ impl fmt::Display for Config {
), ),
#[cfg(feature = "rocksdb")] #[cfg(feature = "rocksdb")]
("RocksDB Recovery Mode", &self.rocksdb_recovery_mode.to_string()), ("RocksDB Recovery Mode", &self.rocksdb_recovery_mode.to_string()),
("RocksDB Repair Mode", &self.rocksdb_repair.to_string()),
("RocksDB Read-only Mode", &self.rocksdb_read_only.to_string()),
("Prevent Media Downloads From", { ("Prevent Media Downloads From", {
let mut lst = vec![]; let mut lst = vec![];
for domain in &self.prevent_media_downloads_from { for domain in &self.prevent_media_downloads_from {

View file

@ -7,16 +7,17 @@ use std::{
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use rust_rocksdb::{ use rust_rocksdb::{
backup::{BackupEngine, BackupEngineOptions}, backup::{BackupEngine, BackupEngineOptions},
DBWithThreadMode as Db,
LogLevel::{Debug, Error, Fatal, Info, Warn}, LogLevel::{Debug, Error, Fatal, Info, Warn},
WriteBatchWithTransaction, MultiThreaded, WriteBatchWithTransaction,
}; };
use tracing::{debug, error, info}; use tracing::{debug, error, info, warn};
use super::{super::Config, watchers::Watchers, KeyValueDatabaseEngine, KvTree}; use super::{super::Config, watchers::Watchers, KeyValueDatabaseEngine, KvTree};
use crate::{utils, Result}; use crate::{utils, Result};
pub(crate) struct Engine { pub(crate) struct Engine {
rocks: rust_rocksdb::DBWithThreadMode<rust_rocksdb::MultiThreaded>, rocks: Db<MultiThreaded>,
row_cache: rust_rocksdb::Cache, row_cache: rust_rocksdb::Cache,
col_cache: rust_rocksdb::Cache, col_cache: rust_rocksdb::Cache,
old_cfs: Vec<String>, old_cfs: Vec<String>,
@ -145,19 +146,30 @@ impl KeyValueDatabaseEngine for Arc<Engine> {
let db_opts = db_options(config, &db_env, &row_cache, &col_cache); let db_opts = db_options(config, &db_env, &row_cache, &col_cache);
debug!("Listing column families in database"); debug!("Listing column families in database");
let cfs = let cfs = Db::<MultiThreaded>::list_cf(&db_opts, &config.database_path).unwrap_or_default();
rust_rocksdb::DBWithThreadMode::<rust_rocksdb::MultiThreaded>::list_cf(&db_opts, &config.database_path)
.unwrap_or_default();
debug!("Opening column family descriptors in database"); if config.rocksdb_repair {
warn!("Starting database repair. This may take a long time...");
if let Err(e) = Db::<MultiThreaded>::repair(&db_opts, &config.database_path) {
error!("Repair failed: {:?}", e);
}
}
debug!("Opening {} column family descriptors in database", cfs.len());
info!("RocksDB database compaction will take place now, a delay in startup is expected"); info!("RocksDB database compaction will take place now, a delay in startup is expected");
let db = rust_rocksdb::DBWithThreadMode::<rust_rocksdb::MultiThreaded>::open_cf_descriptors(
&db_opts,
&config.database_path,
cfs.iter()
.map(|name| rust_rocksdb::ColumnFamilyDescriptor::new(name, db_opts.clone())),
)?;
let cfds = cfs
.iter()
.map(|name| rust_rocksdb::ColumnFamilyDescriptor::new(name, db_opts.clone()))
.collect::<Vec<_>>();
let db = if config.rocksdb_read_only {
Db::<MultiThreaded>::open_cf_for_read_only(&db_opts, &config.database_path, cfs.clone(), false)?
} else {
Db::<MultiThreaded>::open_cf_descriptors(&db_opts, &config.database_path, cfds)?
};
debug!("Opened database at sequence number {}", db.latest_sequence_number());
Ok(Arc::new(Engine { Ok(Arc::new(Engine {
rocks: db, rocks: db,
row_cache, row_cache,