diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index 98f8fc7972..a5b979c2ff 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -743,17 +743,23 @@ fn analyze_column< db: &Database, name: &str, ) { + let mut key_len: u64 = 0; 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 = 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(); - val_tot += b; - row_hist.increment(a + b).unwrap(); + for (key, val) in db.iter::(blockstore_db::IteratorMode::Start).unwrap() { + // Key length is fixed, only need to calculate it once + if key_len == 0 { + key_len = C::key(key).len() as u64; + } + let val_len = val.len() as u64; + + key_tot += key_len; + val_hist.increment(val_len).unwrap(); + val_tot += val_len; + + row_hist.increment(key_len + val_len).unwrap(); } let json_result = if val_hist.entries() > 0 { @@ -761,7 +767,7 @@ fn analyze_column< "column":name, "entries":val_hist.entries(), "key_stats":{ - "max":a, + "max":key_len, "total_bytes":key_tot, }, "val_stats":{ @@ -790,7 +796,7 @@ fn analyze_column< "column":name, "entries":val_hist.entries(), "key_stats":{ - "max":a, + "max":key_len, "total_bytes":0, }, "val_stats":{ diff --git a/ledger/src/blockstore_db.rs b/ledger/src/blockstore_db.rs index 3e1d8812f6..87b26ce4d5 100644 --- a/ledger/src/blockstore_db.rs +++ b/ledger/src/blockstore_db.rs @@ -712,10 +712,6 @@ impl Rocks { pub trait Column { type Index; - fn key_size() -> usize { - std::mem::size_of::() - } - fn key(index: Self::Index) -> Vec; fn index(key: &[u8]) -> Self::Index; // This trait method is primarily used by `Database::delete_range_cf()`, and is therefore only