Refactor: add account_iter api for appendvec (#26591)

* add account iterator for appendvec

* semicolon
This commit is contained in:
HaoranYi 2022-07-12 18:56:05 -05:00 committed by GitHub
parent 6b0eb5a42b
commit 1aa9215411
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 13 deletions

View File

@ -41,9 +41,7 @@ use {
get_ancient_append_vec_capacity, is_ancient, is_full_ancient, AccountsToStore,
StorageSelector,
},
append_vec::{
AppendVec, AppendVecAccountsIter, StoredAccountMeta, StoredMeta, StoredMetaWriteVersion,
},
append_vec::{AppendVec, StoredAccountMeta, StoredMeta, StoredMetaWriteVersion},
bank::Rewrites,
cache_hash_data::CacheHashData,
contains::Contains,
@ -2441,7 +2439,7 @@ impl AccountsDb {
let dirty_stores_len = dirty_stores.len();
let pubkeys = DashSet::new();
for (_slot, store) in dirty_stores {
AppendVecAccountsIter::new(&store.accounts).for_each(|account| {
store.accounts.account_iter().for_each(|account| {
pubkeys.insert(account.meta.pubkey);
});
}
@ -3123,7 +3121,7 @@ impl AccountsDb {
.map(|store| {
original_bytes += store.total_bytes();
let store_id = store.append_vec_id();
AppendVecAccountsIter::new(&store.accounts).for_each(|account| {
store.accounts.account_iter().for_each(|account| {
let new_entry = FoundStoredAccount { account, store_id };
match stored_accounts.entry(new_entry.account.meta.pubkey) {
Entry::Occupied(mut occupied_entry) => {
@ -4205,7 +4203,7 @@ impl AccountsDb {
.unwrap_or_default();
self.thread_pool.install(|| {
storage_maps.par_iter().for_each(|storage| {
AppendVecAccountsIter::new(&storage.accounts).for_each(|account| {
storage.accounts.account_iter().for_each(|account| {
storage_scan_func(&retval, LoadedAccount::Stored(account))
})
});
@ -6304,7 +6302,7 @@ impl AccountsDb {
let mut len = storages.len();
if len == 1 {
// only 1 storage, so no need to interleave between multiple storages based on write_version
AppendVecAccountsIter::new(&storages[0].accounts).for_each(|account| {
storages[0].accounts.account_iter().for_each(|account| {
if scanner.filter(&account.meta.pubkey) {
scanner.found_account(&LoadedAccount::Stored(account))
}
@ -6315,7 +6313,7 @@ impl AccountsDb {
let mut current =
Vec::<(StoredMetaWriteVersion, Option<StoredAccountMeta<'_>>)>::with_capacity(len);
for storage in storages {
let mut iterator = AppendVecAccountsIter::new(&storage.accounts);
let mut iterator = storage.accounts.account_iter();
if let Some(item) = iterator
.next()
.map(|stored_account| (stored_account.meta.write_version, Some(stored_account)))
@ -7933,7 +7931,7 @@ impl AccountsDb {
.sum();
let mut accounts_map = GenerateIndexAccountsMap::with_capacity(num_accounts);
storage_maps.iter().for_each(|storage| {
AppendVecAccountsIter::new(&storage.accounts).for_each(|stored_account| {
storage.accounts.account_iter().for_each(|stored_account| {
let this_version = stored_account.meta.write_version;
let pubkey = stored_account.meta.pubkey;
assert!(!self.is_filler_account(&pubkey));

View File

@ -482,7 +482,12 @@ impl AppendVec {
self.path.clone()
}
/// Return account metadata for each account, starting from `offset`.
/// Return iterator for account metadata
pub fn account_iter(&self) -> AppendVecAccountsIter {
AppendVecAccountsIter::new(self)
}
/// Return a vector of account metadata for each account, starting from `offset`.
pub fn accounts(&self, mut offset: usize) -> Vec<StoredAccountMeta> {
let mut accounts = vec![];
while let Some((account, next)) = self.get_account(offset) {

View File

@ -408,8 +408,7 @@ impl<'a> SnapshotMinimizer<'a> {
mod tests {
use {
crate::{
append_vec::AppendVecAccountsIter, bank::Bank,
genesis_utils::create_genesis_config_with_leader,
bank::Bank, genesis_utils::create_genesis_config_with_leader,
snapshot_minimizer::SnapshotMinimizer,
},
dashmap::DashSet,
@ -681,7 +680,7 @@ mod tests {
let mut account_count = 0;
snapshot_storages.into_iter().for_each(|storages| {
storages.into_iter().for_each(|storage| {
account_count += AppendVecAccountsIter::new(&storage.accounts).count();
account_count += storage.accounts.account_iter().count();
});
});