From 0a7f00030ec4ea3c569f1a3d57af99d245e689fb Mon Sep 17 00:00:00 2001 From: Stephen Akridge Date: Sun, 22 Mar 2020 10:52:11 -0700 Subject: [PATCH] Add option to disable rocks compaction --- core/src/ledger_cleanup_service.rs | 1 + core/src/validator.rs | 5 ++++- ledger/src/blockstore.rs | 20 ++++++++++++++------ multinode-demo/bootstrap-validator.sh | 3 +++ multinode-demo/validator.sh | 3 +++ validator/src/main.rs | 14 +++++++++++--- 6 files changed, 36 insertions(+), 10 deletions(-) diff --git a/core/src/ledger_cleanup_service.rs b/core/src/ledger_cleanup_service.rs index ea3e1d7203d437..c7a1c2e410f4d7 100644 --- a/core/src/ledger_cleanup_service.rs +++ b/core/src/ledger_cleanup_service.rs @@ -17,6 +17,7 @@ use std::time::Duration; // - To make sure that if a validator needs to reboot from its own snapshot, it has enough slots locally // to catch back up to where it was when it stopped pub const DEFAULT_MAX_LEDGER_SLOTS: u64 = 270_000; +pub const DEFAULT_MIN_LEDGER_SLOTS: u64 = 5_000; // Gives about half an hour of slots to rollback from. // Remove a fixed number of slots at a time, it's more efficient than doing it one-by-one pub const DEFAULT_PURGE_BATCH_SIZE: u64 = 256; diff --git a/core/src/validator.rs b/core/src/validator.rs index 1d434b44dcbddb..305ab8ad3efa32 100644 --- a/core/src/validator.rs +++ b/core/src/validator.rs @@ -79,6 +79,7 @@ pub struct ValidatorConfig { pub halt_on_trusted_validators_accounts_hash_mismatch: bool, pub accounts_hash_fault_injection_slots: u64, // 0 = no fault injection pub frozen_accounts: Vec, + pub no_db_compaction: bool, } impl Default for ValidatorConfig { @@ -104,6 +105,7 @@ impl Default for ValidatorConfig { halt_on_trusted_validators_accounts_hash_mismatch: false, accounts_hash_fault_injection_slots: 0, frozen_accounts: vec![], + no_db_compaction: false, } } } @@ -589,8 +591,9 @@ fn new_banks_from_blockstore( } } - let (blockstore, ledger_signal_receiver, completed_slots_receiver) = + let (mut blockstore, ledger_signal_receiver, completed_slots_receiver) = Blockstore::open_with_signal(blockstore_path).expect("Failed to open ledger database"); + blockstore.set_no_compaction(config.no_db_compaction); let process_options = blockstore_processor::ProcessOptions { poh_verify, diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index 0a57b4657b85db..058b7c0a7bc3f1 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -93,6 +93,7 @@ pub struct Blockstore { pub new_shreds_signals: Vec>, pub completed_slots_senders: Vec>>, pub lowest_cleanup_slot: Arc>, + no_compaction: bool, } pub struct IndexMetaWorkingSetEntry { @@ -228,6 +229,7 @@ impl Blockstore { insert_shreds_lock: Arc::new(Mutex::new(())), last_root, lowest_cleanup_slot: Arc::new(RwLock::new(0)), + no_compaction: false, }; Ok(blockstore) } @@ -245,6 +247,10 @@ impl Blockstore { Ok((blockstore, signal_receiver, completed_slots_receiver)) } + pub fn set_no_compaction(&mut self, no_compaction: bool) { + self.no_compaction = no_compaction; + } + pub fn destroy(ledger_path: &Path) -> Result<()> { // Database::destroy() fails if the path doesn't exist fs::create_dir_all(ledger_path)?; @@ -276,12 +282,14 @@ impl Blockstore { while from_slot < batch_end { match self.run_purge(from_slot, batch_end) { Ok(end) => { - if let Err(e) = self.compact_storage(from_slot, batch_end) { - // This error is not fatal and indicates an internal error - error!( - "Error: {:?}; Couldn't compact storage from {:?} to {:?}", - e, from_slot, batch_end - ); + if !self.no_compaction { + if let Err(e) = self.compact_storage(from_slot, batch_end) { + // This error is not fatal and indicates an internal error + error!( + "Error: {:?}; Couldn't compact storage from {:?} to {:?}", + e, from_slot, batch_end + ); + } } if end { diff --git a/multinode-demo/bootstrap-validator.sh b/multinode-demo/bootstrap-validator.sh index d59846f0211538..8f86d7e63896d6 100755 --- a/multinode-demo/bootstrap-validator.sh +++ b/multinode-demo/bootstrap-validator.sh @@ -37,6 +37,9 @@ while [[ -n $1 ]]; do args+=("$1" "$2") shift 2 elif [[ $1 = --limit-ledger-size ]]; then + args+=("$1" "$2") + shift 2 + elif [[ $1 = --no-db-compaction ]]; then args+=("$1") shift elif [[ $1 = --enable-rpc-get-confirmed-block ]]; then diff --git a/multinode-demo/validator.sh b/multinode-demo/validator.sh index 5ffc24a7cb49f6..823a374aefa320 100755 --- a/multinode-demo/validator.sh +++ b/multinode-demo/validator.sh @@ -127,6 +127,9 @@ while [[ -n $1 ]]; do args+=("$1" "$2") shift 2 elif [[ $1 = --limit-ledger-size ]]; then + args+=("$1" "$2") + shift 2 + elif [[ $1 = --no-db-compaction ]]; then args+=("$1") shift elif [[ $1 = --enable-rpc-get-confirmed-block ]]; then diff --git a/validator/src/main.rs b/validator/src/main.rs index 1cc05e0e24165e..64f249c1b69eb9 100644 --- a/validator/src/main.rs +++ b/validator/src/main.rs @@ -10,7 +10,7 @@ use solana_clap_utils::{ keypair::SKIP_SEED_PHRASE_VALIDATION_ARG, }; use solana_client::rpc_client::RpcClient; -use solana_core::ledger_cleanup_service::DEFAULT_MAX_LEDGER_SLOTS; +use solana_core::ledger_cleanup_service::{DEFAULT_MAX_LEDGER_SLOTS, DEFAULT_MIN_LEDGER_SLOTS}; use solana_core::{ cluster_info::{ClusterInfo, Node, VALIDATOR_PORT_RANGE}, contact_info::ContactInfo, @@ -639,6 +639,12 @@ pub fn main() { .takes_value(false) .help("Use the RPC service of trusted validators only") ) + .arg( + Arg::with_name("no_db_compaction") + .long("no-db-compaction") + .takes_value(false) + .help("Disable manual compaction of the ledger database. May increase storage requirements.") + ) .arg( clap::Arg::with_name("bind_address") .long("bind-address") @@ -696,6 +702,7 @@ pub fn main() { let no_snapshot_fetch = matches.is_present("no_snapshot_fetch"); let no_check_vote_account = matches.is_present("no_check_vote_account"); let private_rpc = matches.is_present("private_rpc"); + let no_db_compaction = matches.is_present("no_db_compaction"); // Canonicalize ledger path to avoid issues with symlink creation let _ = fs::create_dir_all(&ledger_path); @@ -746,6 +753,7 @@ pub fn main() { wait_for_supermajority: value_t!(matches, "wait_for_supermajority", Slot).ok(), trusted_validators, frozen_accounts: values_t!(matches, "frozen_accounts", Pubkey).unwrap_or_default(), + no_db_compaction, ..ValidatorConfig::default() }; @@ -820,10 +828,10 @@ pub fn main() { if matches.is_present("limit_ledger_size") { let limit_ledger_size = value_t_or_exit!(matches, "limit_ledger_size", u64); - if limit_ledger_size < DEFAULT_MAX_LEDGER_SLOTS { + if limit_ledger_size < DEFAULT_MIN_LEDGER_SLOTS { eprintln!( "The provided --limit-ledger-size value was too small, the minimum value is {}", - DEFAULT_MAX_LEDGER_SLOTS + DEFAULT_MIN_LEDGER_SLOTS ); exit(1); }