Skip to content

Commit

Permalink
use LoadHint
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington committed Mar 29, 2024
1 parent cdf81bd commit 1182d20
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
8 changes: 8 additions & 0 deletions accounts-db/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ impl Accounts {
self.load_slow(ancestors, pubkey, LoadHint::FixedMaxRoot)
}

pub fn load_with_fixed_root_do_not_populate_read_cache(
&self,
ancestors: &Ancestors,
pubkey: &Pubkey,
) -> Option<(AccountSharedData, Slot)> {
self.load_slow(ancestors, pubkey, LoadHint::FixedMaxRootDoNotPopulateReadCache)
}

pub fn load_without_fixed_root(
&self,
ancestors: &Ancestors,
Expand Down
13 changes: 5 additions & 8 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,8 @@ pub enum LoadHint {
// account loading, while maintaining the determinism of account loading and resultant
// transaction execution thereof.
FixedMaxRoot,
/// same as `FixedMaxRoot`, except do not populate the read cache on load
FixedMaxRootDoNotPopulateReadCache,
// Caller can't hint the above safety assumption. Generally RPC and miscellaneous
// other call-site falls into this category. The likelihood of slower path is slightly
// increased as well.
Expand Down Expand Up @@ -5148,7 +5150,7 @@ impl AccountsDb {
// so retry. This works because in accounts cache flush, an account is written to
// storage *before* it is removed from the cache
match load_hint {
LoadHint::FixedMaxRoot => {
LoadHint::FixedMaxRootDoNotPopulateReadCache | LoadHint::FixedMaxRoot => {
// it's impossible for this to fail for transaction loads from
// replaying/banking more than once.
// This is because:
Expand All @@ -5168,7 +5170,7 @@ impl AccountsDb {
}
LoadedAccountAccessor::Stored(None) => {
match load_hint {
LoadHint::FixedMaxRoot => {
LoadHint::FixedMaxRootDoNotPopulateReadCache | LoadHint::FixedMaxRoot => {
// When running replay on the validator, or banking stage on the leader,
// it should be very rare that the storage entry doesn't exist if the
// entry in the accounts index is the latest version of this account.
Expand Down Expand Up @@ -5377,12 +5379,7 @@ impl AccountsDb {
return None;
}

if !is_cached
&& self
.disable_read_cache_updates_count
.load(Ordering::Relaxed)
== 0
{
if !is_cached && load_hint != LoadHint::FixedMaxRootDoNotPopulateReadCache {
/*
We show this store into the read-only cache for account 'A' and future loads of 'A' from the read-only cache are
safe/reflect 'A''s latest state on this fork.
Expand Down
11 changes: 5 additions & 6 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1827,17 +1827,16 @@ impl Bank {
// Note that we are disabling the read cache while we populate the stakes cache.
// The stakes accounts will not be expected to be loaded again.
// If we populate the read cache with these loads, then we'll just soon have to evict these.
let stakes = {
let _guard = DisableReadCacheUpdates::new(&bank_rc.accounts.accounts_db);
Stakes::new(&fields.stakes, |pubkey| {
let (account, _slot) = bank_rc.accounts.load_with_fixed_root(&ancestors, pubkey)?;
let stakes = Stakes::new(&fields.stakes, |pubkey| {
let (account, _slot) = bank_rc
.accounts
.load_with_fixed_root_do_not_populate_read_cache(&ancestors, pubkey)?;
Some(account)
})
.expect(
"Stakes cache is inconsistent with accounts-db. This can indicate \
a corrupted snapshot or bugs in cached accounts or accounts-db.",
)
};
);
let stakes_accounts_load_duration = now.elapsed();
let mut bank = Self {
skipped_rewrites: Mutex::default(),
Expand Down

0 comments on commit 1182d20

Please sign in to comment.