add AccountStorage.is_empty (#29478)

This commit is contained in:
Jeff Washington (jwash) 2023-01-03 10:35:10 -06:00 committed by GitHub
parent 8c878daada
commit 04508ccfa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View File

@ -46,6 +46,13 @@ impl AccountStorage {
self.map.iter().map(|iter_item| *iter_item.key()).collect()
}
/// returns true if there are no append vecs for 'slot'
pub(crate) fn is_empty(&self, slot: Slot) -> bool {
self.get_slot_stores(slot)
.map(|storages| storages.read().unwrap().is_empty())
.unwrap_or(true)
}
/// initialize the storage map to 'all_storages'
pub(crate) fn initialize(&mut self, all_storages: AccountStorageMap) {
assert!(self.map.is_empty());

View File

@ -8861,11 +8861,7 @@ impl AccountsDb {
.take(per_pass)
.collect::<Vec<_>>();
roots_in_this_pass.into_par_iter().for_each(|slot| {
let storage_maps = self
.storage
.get_slot_storage_entries(*slot)
.unwrap_or_default();
if storage_maps.is_empty() {
if self.storage.is_empty(*slot) {
return;
}
@ -14375,7 +14371,7 @@ pub mod tests {
db.store_cached((0, &[(&other_account_key, &slot0_account)][..]), None);
db.add_root(0);
db.flush_accounts_cache(true, None);
assert!(!db.storage.get_slot_storage_entries(0).unwrap().is_empty());
assert!(!db.storage.is_empty(0));
// Store into slot 1, a dummy slot that will be dead and purged before flush
db.store_cached(