get_storages_for_slot uses get_slot_storage_entry (#29498)

This commit is contained in:
Jeff Washington (jwash) 2023-01-04 12:15:56 -06:00 committed by GitHub
parent f505c2d233
commit 093b1a5e10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 32 deletions

View File

@ -1,7 +1,5 @@
//! Manage the map of slot -> append vecs
#[cfg(test)]
use crate::accounts_db::SnapshotStorage;
use {
crate::accounts_db::{AccountStorageEntry, AppendVecId, SlotStores},
dashmap::DashMap,
@ -44,13 +42,6 @@ impl AccountStorage {
})
}
/// return all append vecs for 'slot' if any exist
#[cfg(test)]
pub(crate) fn get_slot_storage_entries(&self, slot: Slot) -> Option<SnapshotStorage> {
self.get_slot_stores(slot)
.map(|res| res.read().unwrap().values().cloned().collect())
}
pub(crate) fn all_slots(&self) -> Vec<Slot> {
self.map.iter().map(|iter_item| *iter_item.key()).collect()
}

View File

@ -4266,7 +4266,9 @@ impl AccountsDb {
#[cfg(test)]
fn get_storages_for_slot(&self, slot: Slot) -> Option<SnapshotStorage> {
self.storage.get_slot_storage_entries(slot)
self.storage
.get_slot_storage_entry(slot)
.map(|storage| vec![storage])
}
/// 'accounts' that exist in the current slot we are combining into a different ancient slot
@ -14216,9 +14218,7 @@ pub mod tests {
}
fn slot_stores(db: &AccountsDb, slot: Slot) -> SnapshotStorage {
db.storage
.get_slot_storage_entries(slot)
.unwrap_or_default()
db.get_storages_for_slot(slot).unwrap_or_default()
}
#[test]
@ -14573,10 +14573,8 @@ pub mod tests {
impl AccountsDb {
fn get_and_assert_single_storage(&self, slot: Slot) -> Arc<AccountStorageEntry> {
let mut storage_maps: SnapshotStorage = self
.storage
.get_slot_storage_entries(slot)
.unwrap_or_default();
let mut storage_maps: SnapshotStorage =
self.get_storages_for_slot(slot).unwrap_or_default();
assert_eq!(storage_maps.len(), 1);
storage_maps.pop().unwrap()
@ -15856,10 +15854,7 @@ pub mod tests {
accounts.store_for_tests(slot0, &[(&shared_key, &account)]);
accounts.add_root_and_flush_write_cache(slot0);
let storage_maps = accounts
.storage
.get_slot_storage_entries(slot0)
.unwrap_or_default();
let storage_maps = accounts.get_storages_for_slot(slot0).unwrap_or_default();
let storage_info = StorageSizeAndCountMap::default();
let accounts_map = accounts.process_storage_slot(&storage_maps[..]);
AccountsDb::update_storage_info(&storage_info, &accounts_map, &Mutex::default());
@ -15908,10 +15903,7 @@ pub mod tests {
accounts.store_for_tests(slot0, &[(&keys[1], &account_big)]);
accounts.add_root_and_flush_write_cache(slot0);
let storage_maps = accounts
.storage
.get_slot_storage_entries(slot0)
.unwrap_or_default();
let storage_maps = accounts.get_storages_for_slot(slot0).unwrap_or_default();
let storage_info = StorageSizeAndCountMap::default();
let accounts_map = accounts.process_storage_slot(&storage_maps[..]);
AccountsDb::update_storage_info(&storage_info, &accounts_map, &Mutex::default());
@ -16013,7 +16005,7 @@ pub mod tests {
/// asserts that not only are there 0 append vecs, but there is not even an entry in the storage map for 'slot'
fn assert_no_storages_at_slot(db: &AccountsDb, slot: Slot) {
assert!(db.storage.get_slot_storage_entries(slot).is_none());
assert!(db.get_storages_for_slot(slot).is_none());
}
/// Test to make sure `clean_accounts()` works properly with the `last_full_snapshot_slot`
@ -17401,12 +17393,7 @@ pub mod tests {
let max_slot_inclusive = ancient_slot + (num_normal_slots as Slot);
let initial_accounts = get_all_accounts(&db, ancient_slot..(max_slot_inclusive + 1));
let ancient = db
.get_storages_for_slot(ancient_slot)
.unwrap()
.first()
.unwrap()
.clone();
let ancient = db.storage.get_slot_storage_entry(ancient_slot).unwrap();
let initial_len = ancient.alive_bytes();
// set size of ancient to be 'full'
adjust_append_vec_len_for_tests(&ancient, ancient.accounts.capacity() as usize);