From 16a7701587e6bf9f6872298163bc83c8f6cb82bd Mon Sep 17 00:00:00 2001 From: jeff washington Date: Tue, 3 Jan 2023 11:52:03 -0600 Subject: [PATCH] get_storages_for_slot uses get_slot_storage_entry --- runtime/src/account_storage.rs | 8 +------- runtime/src/accounts_db.rs | 33 ++++++++++----------------------- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/runtime/src/account_storage.rs b/runtime/src/account_storage.rs index 2941d8ca0c6b66..1452c2a8b5e2e0 100644 --- a/runtime/src/account_storage.rs +++ b/runtime/src/account_storage.rs @@ -1,7 +1,7 @@ //! Manage the map of slot -> append vecs use { - crate::accounts_db::{AccountStorageEntry, AppendVecId, SlotStores, SnapshotStorage}, + crate::accounts_db::{AccountStorageEntry, AppendVecId, SlotStores}, dashmap::DashMap, solana_sdk::clock::Slot, std::{ @@ -42,12 +42,6 @@ impl AccountStorage { }) } - /// return all append vecs for 'slot' if any exist - pub(crate) fn get_slot_storage_entries(&self, slot: Slot) -> Option { - self.get_slot_stores(slot) - .map(|res| res.read().unwrap().values().cloned().collect()) - } - pub(crate) fn all_slots(&self) -> Vec { self.map.iter().map(|iter_item| *iter_item.key()).collect() } diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 17c48021356730..7bc39b1803ffaf 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -4265,7 +4265,9 @@ impl AccountsDb { } fn get_storages_for_slot(&self, slot: Slot) -> Option { - 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 @@ -14221,9 +14223,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] @@ -14578,10 +14578,8 @@ pub mod tests { impl AccountsDb { fn get_and_assert_single_storage(&self, slot: Slot) -> Arc { - 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() @@ -15861,10 +15859,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()); @@ -15913,10 +15908,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()); @@ -16018,7 +16010,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` @@ -17406,12 +17398,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);