From c7ca2f41f5f763151d9de579b95b8ca589815762 Mon Sep 17 00:00:00 2001 From: steviez Date: Sun, 6 Feb 2022 23:28:24 -0600 Subject: [PATCH] Add some comments for RocksDB option configuration (#22655) --- ledger/src/blockstore_db.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ledger/src/blockstore_db.rs b/ledger/src/blockstore_db.rs index 3a157fbcc..a0c34b1f9 100644 --- a/ledger/src/blockstore_db.rs +++ b/ledger/src/blockstore_db.rs @@ -339,9 +339,6 @@ impl Rocks { warn!("Trying as secondary at : {:?}", secondary_path); warn!("This active secondary db use may temporarily cause the performance of another db use (like by validator) to degrade"); - // This is needed according to https://github.com/facebook/rocksdb/wiki/Secondary-instance - db_options.set_max_open_files(-1); - Rocks( DB::open_cf_as_secondary( &db_options, @@ -1350,6 +1347,7 @@ fn get_cf_options( }); } + // Disable automatic compactions in maintenance mode to prevent accidental cleaning if matches!(access_type, AccessType::PrimaryOnlyForMaintenance) { options.set_disable_auto_compactions(true); } @@ -1359,13 +1357,15 @@ fn get_cf_options( fn get_db_options(access_type: &AccessType) -> Options { let mut options = Options::default(); + + // Create missing items to support a clean start options.create_if_missing(true); options.create_missing_column_families(true); - // A good value for this is the number of cores on the machine + + // Per the docs, a good value for this is the number of cores on the machine options.increase_parallelism(num_cpus::get() as i32); let mut env = rocksdb::Env::default().unwrap(); - // While a compaction is ongoing, all the background threads // could be used by the compaction. This can stall writes which // need to flush the memtable. Add some high-priority background threads @@ -1375,10 +1375,17 @@ fn get_db_options(access_type: &AccessType) -> Options { // Set max total wal size to 4G. options.set_max_total_wal_size(4 * 1024 * 1024 * 1024); + + // Disable automatic compactions in maintenance mode to prevent accidental cleaning if matches!(access_type, AccessType::PrimaryOnlyForMaintenance) { options.set_disable_auto_compactions(true); } + // Allow Rocks to open/keep open as many files as it needs for performance; + // however, this is also explicitly required for a secondary instance. + // See https://github.com/facebook/rocksdb/wiki/Secondary-instance + options.set_max_open_files(-1); + options }