Skip to content

Commit

Permalink
skip loading old accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoranYi committed Mar 11, 2024
1 parent 135b3ca commit 8c673d6
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2389,6 +2389,8 @@ pub type LTHashCacheMap =

pub struct LTHashCacheStat {
hits: u64,
load_old_accounts: u64,
skip_load_old_accounts: u64,
before_size: u64,
after_size: u64,
}
Expand All @@ -2397,8 +2399,13 @@ impl std::fmt::Display for LTHashCacheStat {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
f,
"LTHashCacheStat {{ hits: {}, before_size: {}, after_size: {} }}",
self.hits, self.before_size, self.after_size
"LTHashCacheStat {{ hits: {}, load_old_accounts: {}, \
skip_load_old_accounts: {} before_size: {}, after_size: {} }}",
self.hits,
self.load_old_accounts,
self.skip_load_old_accounts,
self.before_size,
self.after_size
)
}
}
Expand Down Expand Up @@ -8151,6 +8158,8 @@ impl AccountsDb {
let mut old_ancestors = ancestors.clone();
old_ancestors.remove(&slot);
let mut cache_hits: u64 = 0;
let mut old_account_loads: u64 = 0;
let mut skip_old_account_loads: u64 = 0;
let r_written_accounts_before = written_accounts_before.read().unwrap();
// if we want to look it up ourselves: let (hashes, _scan_us, _accumulate) = self.get_pubkey_hash_for_slot(slot);
let old = pubkeys
Expand All @@ -8161,10 +8170,14 @@ impl AccountsDb {
if let Some(hash) = hash {
cache_hits += 1;
return Some(*hash); // TODO on demand calculate, calculate in bg
} else {
warn!("Expect in lt hash cache {} {:?} {:?}", k, account, hash);
}

if let Some(account) = account {
skip_old_account_loads += 1;
return Some(Self::lt_hash_account(account, k));
}
}
old_account_loads += 1;
self.load_with_fixed_root(&old_ancestors, k)
.map(|(account, _)| Self::lt_hash_account(&account, k))
})
Expand All @@ -8179,16 +8192,18 @@ impl AccountsDb {
}
let new = self
.load_with_fixed_root(ancestors, k)
.map(|(account, _)| Self::lt_hash_account(&account, k));
.map(|(account, _)| (Self::lt_hash_account(&account, k), account));
if let Some(new) = new {
accumulated_accounts_hash.add(&new);
w_written_accounts_after.insert(*k, (None, Some(new)));
accumulated_accounts_hash.add(&new.0);
w_written_accounts_after.insert(*k, (Some(new.1), Some(new.0)));
}
});
drop(w_written_accounts_after);

LTHashCacheStat {
hits: cache_hits,
load_old_accounts: old_account_loads,
skip_load_old_accounts: skip_old_account_loads,
before_size: written_accounts_before.read().unwrap().len() as u64,
after_size: written_accounts_after.read().unwrap().len() as u64,
}
Expand Down

0 comments on commit 8c673d6

Please sign in to comment.