Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove key_size() method from Column trait #34021

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,25 +743,31 @@ 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::<C>(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::<C>(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 {
json!({
"column":name,
"entries":val_hist.entries(),
"key_stats":{
"max":a,
"max":key_len,
"total_bytes":key_tot,
},
"val_stats":{
Expand Down Expand Up @@ -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":{
Expand Down
4 changes: 0 additions & 4 deletions ledger/src/blockstore_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,10 +719,6 @@ impl Rocks {
pub trait Column {
type Index;

fn key_size() -> usize {
std::mem::size_of::<Self::Index>()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just simply remove this problematic default implementation.

}

fn key(index: Self::Index) -> Vec<u8>;
fn index(key: &[u8]) -> Self::Index;
// This trait method is primarily used by `Database::delete_range_cf()`, and is therefore only
Expand Down