From 9f1f64e3844bd985f1a1b7fb42e0b57b6966da0c Mon Sep 17 00:00:00 2001 From: steviez Date: Thu, 6 Jan 2022 23:40:02 -0600 Subject: [PATCH] Cleanup ledger-tool analyze-storage command (#22310) * Make ledger-tool analyze-storage use Blockstore::open() Opening a large ledger may require setting a larger open file descriptor limit. Blockstore::open() does this whereas the underlying Database object that analyze-storage was opening does not. * Move key_size call lookup to take advantage of traits * Fix typo where analyze worked on wrong column * Make analyze-storage analyze all columns --- ledger-tool/src/main.rs | 83 +++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 52 deletions(-) diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index 5d49ed784..7b145ef74 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -22,9 +22,7 @@ use { ancestor_iterator::AncestorIterator, bank_forks_utils, blockstore::{create_new_ledger, Blockstore, PurgeType}, - blockstore_db::{ - self, AccessType, BlockstoreOptions, BlockstoreRecoveryMode, Column, Database, - }, + blockstore_db::{self, AccessType, BlockstoreOptions, BlockstoreRecoveryMode, Database}, blockstore_processor::ProcessOptions, shred::Shred, }, @@ -577,18 +575,17 @@ fn graph_forks(bank_forks: &BankForks, include_all_votes: bool) -> String { } fn analyze_column< - T: solana_ledger::blockstore_db::Column + solana_ledger::blockstore_db::ColumnName, + C: solana_ledger::blockstore_db::Column + solana_ledger::blockstore_db::ColumnName, >( db: &Database, name: &str, - key_size: usize, ) { let mut key_tot: u64 = 0; let mut val_hist = histogram::Histogram::new(); let mut val_tot: u64 = 0; let mut row_hist = histogram::Histogram::new(); - let a = key_size as u64; - for (_x, y) in db.iter::(blockstore_db::IteratorMode::Start).unwrap() { + let a = C::key_size() as u64; + for (_x, y) in db.iter::(blockstore_db::IteratorMode::Start).unwrap() { let b = y.len() as u64; key_tot += a; val_hist.increment(b).unwrap(); @@ -647,30 +644,25 @@ fn analyze_column< fn analyze_storage(database: &Database) { use blockstore_db::columns::*; - analyze_column::(database, "SlotMeta", SlotMeta::key_size()); - analyze_column::(database, "Orphans", Orphans::key_size()); - analyze_column::(database, "DeadSlots", DeadSlots::key_size()); - analyze_column::(database, "ErasureMeta", ErasureMeta::key_size()); - analyze_column::(database, "Root", Root::key_size()); - analyze_column::(database, "Index", Index::key_size()); - analyze_column::(database, "ShredData", ShredData::key_size()); - analyze_column::(database, "ShredCode", ShredCode::key_size()); - analyze_column::( - database, - "TransactionStatus", - TransactionStatus::key_size(), - ); - analyze_column::( - database, - "TransactionStatusIndex", - TransactionStatusIndex::key_size(), - ); - analyze_column::( - database, - "AddressSignatures", - AddressSignatures::key_size(), - ); - analyze_column::(database, "Rewards", Rewards::key_size()); + analyze_column::(database, "SlotMeta"); + analyze_column::(database, "Orphans"); + analyze_column::(database, "DeadSlots"); + analyze_column::(database, "DuplicateSlots"); + analyze_column::(database, "ErasureMeta"); + analyze_column::(database, "BankHash"); + analyze_column::(database, "Root"); + analyze_column::(database, "Index"); + analyze_column::(database, "ShredData"); + analyze_column::(database, "ShredCode"); + analyze_column::(database, "TransactionStatus"); + analyze_column::(database, "AddressSignatures"); + analyze_column::(database, "TransactionMemos"); + analyze_column::(database, "TransactionStatusIndex"); + analyze_column::(database, "Rewards"); + analyze_column::(database, "Blocktime"); + analyze_column::(database, "PerfSamples"); + analyze_column::(database, "BlockHeight"); + analyze_column::(database, "ProgramCosts"); } fn open_blockstore( @@ -694,23 +686,6 @@ fn open_blockstore( } } -fn open_database(ledger_path: &Path, access_type: AccessType) -> Database { - match Database::open( - &ledger_path.join("rocksdb"), - BlockstoreOptions { - access_type, - recovery_mode: None, - ..BlockstoreOptions::default() - }, - ) { - Ok(database) => database, - Err(err) => { - eprintln!("Unable to read the Ledger rocksdb: {:?}", err); - exit(1); - } - } -} - // This function is duplicated in validator/src/main.rs... fn hardforks_of(matches: &ArgMatches<'_>, name: &str) -> Option> { if matches.is_present(name) { @@ -3317,10 +3292,14 @@ fn main() { }; } ("analyze-storage", _) => { - analyze_storage(&open_database( - &ledger_path, - AccessType::TryPrimaryThenSecondary, - )); + analyze_storage( + &open_blockstore( + &ledger_path, + AccessType::TryPrimaryThenSecondary, + wal_recovery_mode, + ) + .db(), + ); println!("Ok."); } ("compute-slot-cost", Some(arg_matches)) => {