diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index ee65adfc18..1e574fe035 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -552,7 +552,9 @@ impl<'a> LoadedAccount<'a> { } #[derive(Clone, Default, Debug)] -pub struct AccountStorage(pub DashMap); +pub struct AccountStorage { + pub map: DashMap, +} impl AccountStorage { fn get_account_storage_entry( @@ -565,7 +567,7 @@ impl AccountStorage { } pub fn get_slot_stores(&self, slot: Slot) -> Option { - self.0.get(&slot).map(|result| result.value().clone()) + self.map.get(&slot).map(|result| result.value().clone()) } fn get_slot_storage_entries(&self, slot: Slot) -> Option>> { @@ -579,7 +581,7 @@ impl AccountStorage { } fn all_slots(&self) -> Vec { - self.0.iter().map(|iter_item| *iter_item.key()).collect() + self.map.iter().map(|iter_item| *iter_item.key()).collect() } } @@ -3944,7 +3946,7 @@ impl AccountsDb { // However, we still want to persist the reference to the `SlotStores` behind // the lock, hence we clone it out, (`SlotStores` is an Arc so is cheap to clone). self.storage - .0 + .map .entry(slot) .or_insert(Arc::new(RwLock::new(HashMap::new()))) .clone()); @@ -4095,7 +4097,7 @@ impl AccountsDb { let mut remove_storage_entries_elapsed = Measure::start("remove_storage_entries_elapsed"); for remove_slot in removed_slots { // Remove the storage entries and collect some metrics - if let Some((_, slot_storages_to_be_removed)) = self.storage.0.remove(remove_slot) { + if let Some((_, slot_storages_to_be_removed)) = self.storage.map.remove(remove_slot) { { let r_slot_removed_storages = slot_storages_to_be_removed.read().unwrap(); total_removed_storage_entries += r_slot_removed_storages.len(); @@ -4999,7 +5001,7 @@ impl AccountsDb { let mut oldest_slot = std::u64::MAX; let mut total_bytes = 0; let mut total_alive_bytes = 0; - for iter_item in self.storage.0.iter() { + for iter_item in self.storage.map.iter() { let slot = iter_item.key(); let slot_stores = iter_item.value().read().unwrap(); total_count += slot_stores.len(); @@ -6556,7 +6558,7 @@ impl AccountsDb { let mut m = Measure::start("get slots"); let slots = self .storage - .0 + .map .iter() .map(|k| *k.key() as Slot) .collect::>(); @@ -6579,7 +6581,7 @@ impl AccountsDb { .map(|ancestors| ancestors.contains_key(slot)) .unwrap_or_default()) { - self.storage.0.get(slot).map_or_else( + self.storage.map.get(slot).map_or_else( || None, |item| { let storages = item @@ -7144,7 +7146,7 @@ impl AccountsDb { ) { // store count and size for each storage let mut storage_size_storages_time = Measure::start("storage_size_storages"); - for slot_stores in self.storage.0.iter() { + for slot_stores in self.storage.map.iter() { for (id, store) in slot_stores.value().read().unwrap().iter() { // Should be default at this point assert_eq!(store.alive_bytes(), 0); @@ -8362,7 +8364,7 @@ pub mod tests { assert!(db.load_without_fixed_root(&ancestors, &key).is_none()); assert!(db.bank_hashes.read().unwrap().get(&unrooted_slot).is_none()); assert!(db.accounts_cache.slot_cache(unrooted_slot).is_none()); - assert!(db.storage.0.get(&unrooted_slot).is_none()); + assert!(db.storage.map.get(&unrooted_slot).is_none()); assert!(db.accounts_index.get_account_read_entry(&key).is_none()); assert!(db .accounts_index @@ -8607,7 +8609,7 @@ pub mod tests { let mut append_vec_histogram = HashMap::new(); let mut all_storages = vec![]; - for slot_storage in accounts.storage.0.iter() { + for slot_storage in accounts.storage.map.iter() { all_storages.extend(slot_storage.read().unwrap().values().cloned()) } for storage in all_storages { @@ -8638,7 +8640,7 @@ pub mod tests { let account2 = AccountSharedData::new(1, DEFAULT_FILE_SIZE as usize / 2, &pubkey2); accounts.store_uncached(0, &[(&pubkey2, &account2)]); { - assert_eq!(accounts.storage.0.len(), 1); + assert_eq!(accounts.storage.map.len(), 1); let stores = &accounts.storage.get_slot_stores(0).unwrap(); let r_stores = stores.read().unwrap(); assert_eq!(r_stores.len(), 2); @@ -8667,7 +8669,7 @@ pub mod tests { for _ in 0..25 { accounts.store_uncached(0, &[(&pubkey1, &account1)]); { - assert_eq!(accounts.storage.0.len(), 1); + assert_eq!(accounts.storage.map.len(), 1); let stores = &accounts.storage.get_slot_stores(0).unwrap(); let r_stores = stores.read().unwrap(); assert!(r_stores.len() <= 7); @@ -8732,7 +8734,7 @@ pub mod tests { //slot is gone accounts.print_accounts_stats("pre-clean"); accounts.clean_accounts(None, false, None); - assert!(accounts.storage.0.get(&0).is_none()); + assert!(accounts.storage.map.get(&0).is_none()); //new value is there let ancestors = vec![(1, 1)].into_iter().collect(); @@ -13249,7 +13251,7 @@ pub mod tests { accounts.store_uncached(slot0, &[(&shared_key, &account)]); // fake out the store count to avoid the assert - for slot_stores in accounts.storage.0.iter() { + for slot_stores in accounts.storage.map.iter() { for (_id, store) in slot_stores.value().read().unwrap().iter() { store.alive_bytes.store(0, Ordering::Release); } @@ -13265,8 +13267,8 @@ pub mod tests { }, ); accounts.set_storage_count_and_alive_bytes(dashmap, &mut GenerateIndexTimings::default()); - assert_eq!(accounts.storage.0.len(), 1); - for slot_stores in accounts.storage.0.iter() { + assert_eq!(accounts.storage.map.len(), 1); + for slot_stores in accounts.storage.map.iter() { for (id, store) in slot_stores.value().read().unwrap().iter() { assert_eq!(id, &0); assert_eq!(store.count_and_status.read().unwrap().0, 3); diff --git a/runtime/src/serde_snapshot.rs b/runtime/src/serde_snapshot.rs index ded689318f..ff9372edad 100644 --- a/runtime/src/serde_snapshot.rs +++ b/runtime/src/serde_snapshot.rs @@ -515,7 +515,7 @@ where .write() .unwrap() .insert(snapshot_slot, snapshot_bank_hash_info); - accounts_db.storage.0.extend( + accounts_db.storage.map.extend( storage .into_iter() .map(|(slot, slot_storage_entry)| (slot, Arc::new(RwLock::new(slot_storage_entry)))),