Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Add option to disable rocks compaction
Browse files Browse the repository at this point in the history
  • Loading branch information
sakridge committed Mar 22, 2020
1 parent ff2c183 commit 7a58e30
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
5 changes: 4 additions & 1 deletion core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub struct ValidatorConfig {
pub trusted_validators: Option<HashSet<Pubkey>>, // None = trust all
pub halt_on_trusted_validators_accounts_hash_mismatch: bool,
pub accounts_hash_fault_injection_slots: u64, // 0 = no fault injection
pub no_db_compaction: bool,
}

impl Default for ValidatorConfig {
Expand All @@ -102,6 +103,7 @@ impl Default for ValidatorConfig {
trusted_validators: None,
halt_on_trusted_validators_accounts_hash_mismatch: false,
accounts_hash_fault_injection_slots: 0,
no_db_compaction: false,
}
}
}
Expand Down Expand Up @@ -587,8 +589,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,
Expand Down
20 changes: 14 additions & 6 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub struct Blockstore {
pub new_shreds_signals: Vec<SyncSender<bool>>,
pub completed_slots_senders: Vec<SyncSender<Vec<Slot>>>,
pub lowest_cleanup_slot: Arc<RwLock<u64>>,
no_compaction: bool,
}

pub struct IndexMetaWorkingSetEntry {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)?;
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions multinode-demo/bootstrap-validator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ while [[ -n $1 ]]; do
elif [[ $1 = --limit-ledger-size ]]; then
args+=("$1")
shift
elif [[ $1 = --no-db-compaction ]]; then
args+=("$1")
shift
elif [[ $1 = --enable-rpc-get-confirmed-block ]]; then
args+=("$1")
shift
Expand Down
3 changes: 3 additions & 0 deletions multinode-demo/validator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ while [[ -n $1 ]]; do
elif [[ $1 = --limit-ledger-size ]]; then
args+=("$1")
shift
elif [[ $1 = --no-db-compaction ]]; then
args+=("$1")
shift
elif [[ $1 = --enable-rpc-get-confirmed-block ]]; then
args+=("$1")
shift
Expand Down
8 changes: 8 additions & 0 deletions validator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,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")
Expand Down Expand Up @@ -684,6 +690,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);
Expand Down Expand Up @@ -733,6 +740,7 @@ pub fn main() {
voting_disabled: matches.is_present("no_voting"),
wait_for_supermajority: value_t!(matches, "wait_for_supermajority", Slot).ok(),
trusted_validators,
no_db_compaction,
..ValidatorConfig::default()
};

Expand Down

0 comments on commit 7a58e30

Please sign in to comment.