Refactor: add account_iter api for appendvec (#26591)
* add account iterator for appendvec * semicolon
This commit is contained in:
parent
6b0eb5a42b
commit
1aa9215411
|
@ -41,9 +41,7 @@ use {
|
||||||
get_ancient_append_vec_capacity, is_ancient, is_full_ancient, AccountsToStore,
|
get_ancient_append_vec_capacity, is_ancient, is_full_ancient, AccountsToStore,
|
||||||
StorageSelector,
|
StorageSelector,
|
||||||
},
|
},
|
||||||
append_vec::{
|
append_vec::{AppendVec, StoredAccountMeta, StoredMeta, StoredMetaWriteVersion},
|
||||||
AppendVec, AppendVecAccountsIter, StoredAccountMeta, StoredMeta, StoredMetaWriteVersion,
|
|
||||||
},
|
|
||||||
bank::Rewrites,
|
bank::Rewrites,
|
||||||
cache_hash_data::CacheHashData,
|
cache_hash_data::CacheHashData,
|
||||||
contains::Contains,
|
contains::Contains,
|
||||||
|
@ -2441,7 +2439,7 @@ impl AccountsDb {
|
||||||
let dirty_stores_len = dirty_stores.len();
|
let dirty_stores_len = dirty_stores.len();
|
||||||
let pubkeys = DashSet::new();
|
let pubkeys = DashSet::new();
|
||||||
for (_slot, store) in dirty_stores {
|
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);
|
pubkeys.insert(account.meta.pubkey);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -3123,7 +3121,7 @@ impl AccountsDb {
|
||||||
.map(|store| {
|
.map(|store| {
|
||||||
original_bytes += store.total_bytes();
|
original_bytes += store.total_bytes();
|
||||||
let store_id = store.append_vec_id();
|
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 };
|
let new_entry = FoundStoredAccount { account, store_id };
|
||||||
match stored_accounts.entry(new_entry.account.meta.pubkey) {
|
match stored_accounts.entry(new_entry.account.meta.pubkey) {
|
||||||
Entry::Occupied(mut occupied_entry) => {
|
Entry::Occupied(mut occupied_entry) => {
|
||||||
|
@ -4205,7 +4203,7 @@ impl AccountsDb {
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
self.thread_pool.install(|| {
|
self.thread_pool.install(|| {
|
||||||
storage_maps.par_iter().for_each(|storage| {
|
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))
|
storage_scan_func(&retval, LoadedAccount::Stored(account))
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
@ -6304,7 +6302,7 @@ impl AccountsDb {
|
||||||
let mut len = storages.len();
|
let mut len = storages.len();
|
||||||
if len == 1 {
|
if len == 1 {
|
||||||
// only 1 storage, so no need to interleave between multiple storages based on write_version
|
// 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) {
|
if scanner.filter(&account.meta.pubkey) {
|
||||||
scanner.found_account(&LoadedAccount::Stored(account))
|
scanner.found_account(&LoadedAccount::Stored(account))
|
||||||
}
|
}
|
||||||
|
@ -6315,7 +6313,7 @@ impl AccountsDb {
|
||||||
let mut current =
|
let mut current =
|
||||||
Vec::<(StoredMetaWriteVersion, Option<StoredAccountMeta<'_>>)>::with_capacity(len);
|
Vec::<(StoredMetaWriteVersion, Option<StoredAccountMeta<'_>>)>::with_capacity(len);
|
||||||
for storage in storages {
|
for storage in storages {
|
||||||
let mut iterator = AppendVecAccountsIter::new(&storage.accounts);
|
let mut iterator = storage.accounts.account_iter();
|
||||||
if let Some(item) = iterator
|
if let Some(item) = iterator
|
||||||
.next()
|
.next()
|
||||||
.map(|stored_account| (stored_account.meta.write_version, Some(stored_account)))
|
.map(|stored_account| (stored_account.meta.write_version, Some(stored_account)))
|
||||||
|
@ -7933,7 +7931,7 @@ impl AccountsDb {
|
||||||
.sum();
|
.sum();
|
||||||
let mut accounts_map = GenerateIndexAccountsMap::with_capacity(num_accounts);
|
let mut accounts_map = GenerateIndexAccountsMap::with_capacity(num_accounts);
|
||||||
storage_maps.iter().for_each(|storage| {
|
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 this_version = stored_account.meta.write_version;
|
||||||
let pubkey = stored_account.meta.pubkey;
|
let pubkey = stored_account.meta.pubkey;
|
||||||
assert!(!self.is_filler_account(&pubkey));
|
assert!(!self.is_filler_account(&pubkey));
|
||||||
|
|
|
@ -482,7 +482,12 @@ impl AppendVec {
|
||||||
self.path.clone()
|
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> {
|
pub fn accounts(&self, mut offset: usize) -> Vec<StoredAccountMeta> {
|
||||||
let mut accounts = vec![];
|
let mut accounts = vec![];
|
||||||
while let Some((account, next)) = self.get_account(offset) {
|
while let Some((account, next)) = self.get_account(offset) {
|
||||||
|
|
|
@ -408,8 +408,7 @@ impl<'a> SnapshotMinimizer<'a> {
|
||||||
mod tests {
|
mod tests {
|
||||||
use {
|
use {
|
||||||
crate::{
|
crate::{
|
||||||
append_vec::AppendVecAccountsIter, bank::Bank,
|
bank::Bank, genesis_utils::create_genesis_config_with_leader,
|
||||||
genesis_utils::create_genesis_config_with_leader,
|
|
||||||
snapshot_minimizer::SnapshotMinimizer,
|
snapshot_minimizer::SnapshotMinimizer,
|
||||||
},
|
},
|
||||||
dashmap::DashSet,
|
dashmap::DashSet,
|
||||||
|
@ -681,7 +680,7 @@ mod tests {
|
||||||
let mut account_count = 0;
|
let mut account_count = 0;
|
||||||
snapshot_storages.into_iter().for_each(|storages| {
|
snapshot_storages.into_iter().for_each(|storages| {
|
||||||
storages.into_iter().for_each(|storage| {
|
storages.into_iter().for_each(|storage| {
|
||||||
account_count += AppendVecAccountsIter::new(&storage.accounts).count();
|
account_count += storage.accounts.account_iter().count();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue