From 8c673d61178607d0d4e78454957220563d6108ad Mon Sep 17 00:00:00 2001 From: HaoranYi Date: Mon, 11 Mar 2024 21:32:29 +0000 Subject: [PATCH] skip loading old accounts --- accounts-db/src/accounts_db.rs | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index b77a1565659c64..e3ec3bf858f30a 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -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, } @@ -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 ) } } @@ -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 @@ -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)) }) @@ -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, }