Replaces ReadAccountMapEntry in calculate_accounts_hash_from_index() (#35349)

This commit is contained in:
Brooks 2024-02-28 14:38:19 -05:00 committed by GitHub
parent 8f3e960640
commit 6402198902
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 31 deletions

View File

@ -41,11 +41,10 @@ use {
ZeroLamportAccounts, ZeroLamportAccounts,
}, },
accounts_index::{ accounts_index::{
AccountIndexGetResult, AccountMapEntry, AccountSecondaryIndexes, AccountsIndex, AccountMapEntry, AccountSecondaryIndexes, AccountsIndex, AccountsIndexConfig,
AccountsIndexConfig, AccountsIndexRootsStats, AccountsIndexScanResult, DiskIndexValue, AccountsIndexRootsStats, AccountsIndexScanResult, DiskIndexValue, IndexKey, IndexValue,
IndexKey, IndexValue, IsCached, RefCount, ScanConfig, ScanResult, SlotList, IsCached, RefCount, ScanConfig, ScanResult, SlotList, UpsertReclaim, ZeroLamport,
UpsertReclaim, ZeroLamport, ACCOUNTS_INDEX_CONFIG_FOR_BENCHMARKS, ACCOUNTS_INDEX_CONFIG_FOR_BENCHMARKS, ACCOUNTS_INDEX_CONFIG_FOR_TESTING,
ACCOUNTS_INDEX_CONFIG_FOR_TESTING,
}, },
accounts_index_storage::Startup, accounts_index_storage::Startup,
accounts_partition::RentPayingAccountsByPartition, accounts_partition::RentPayingAccountsByPartition,
@ -6864,28 +6863,20 @@ impl AccountsDb {
let result: Vec<Hash> = pubkeys let result: Vec<Hash> = pubkeys
.iter() .iter()
.filter_map(|pubkey| { .filter_map(|pubkey| {
if let AccountIndexGetResult::Found(lock, index) = let index_entry = self.accounts_index.get_cloned(pubkey)?;
self.accounts_index.get(pubkey, config.ancestors, Some(max_slot)) self.accounts_index.get_account_info_with_and_then(
{ &index_entry,
let (slot, account_info) = &lock.slot_list()[index]; config.ancestors,
if !account_info.is_zero_lamport() { Some(max_slot),
// Because we're keeping the `lock' here, there is no need |(slot, account_info)| {
// to use retry_to_get_account_accessor() if account_info.is_zero_lamport() { return None; }
// In other words, flusher/shrinker/cleaner is blocked to
// cause any Accessor(None) situation.
// Anyway this race condition concern is currently a moot
// point because calculate_accounts_hash() should not
// currently race with clean/shrink because the full hash
// is synchronous with clean/shrink in
// AccountsBackgroundService
self.get_account_accessor( self.get_account_accessor(
*slot, slot,
pubkey, pubkey,
&account_info.storage_location(), &account_info.storage_location(),
) )
.get_loaded_account() .get_loaded_account()
.and_then( .and_then(|loaded_account| {
|loaded_account| {
let mut loaded_hash = loaded_account.loaded_hash(); let mut loaded_hash = loaded_account.loaded_hash();
let balance = loaded_account.lamports(); let balance = loaded_account.lamports();
let hash_is_missing = loaded_hash == AccountHash(Hash::default()); let hash_is_missing = loaded_hash == AccountHash(Hash::default());
@ -6905,14 +6896,10 @@ impl AccountsDb {
sum += balance as u128; sum += balance as u128;
Some(loaded_hash.0) Some(loaded_hash.0)
}, })
) },
} else { )
None .flatten()
}
} else {
None
}
}) })
.collect(); .collect();
let mut total = total_lamports.lock().unwrap(); let mut total = total_lamports.lock().unwrap();

View File

@ -1155,7 +1155,7 @@ impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> AccountsIndex<T, U> {
/// Gets the account info (and slot) in `entry`, with `ancestors` and `max_root`, /// Gets the account info (and slot) in `entry`, with `ancestors` and `max_root`,
/// and applies `callback` to it /// and applies `callback` to it
fn get_account_info_with_and_then<R>( pub(crate) fn get_account_info_with_and_then<R>(
&self, &self,
entry: &AccountMapEntryInner<T>, entry: &AccountMapEntryInner<T>,
ancestors: Option<&Ancestors>, ancestors: Option<&Ancestors>,