diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 10768b75d1..57b84daa75 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -1402,7 +1402,7 @@ impl Default for AccountsDb { } type GenerateIndexAccountsMap<'a> = - HashMap<&'a Pubkey, (StoredMetaWriteVersion, AppendVecId, StoredAccountMeta<'a>)>; + HashMap)>; impl AccountsDb { pub fn new(paths: Vec, cluster_type: &ClusterType) -> Self { @@ -5845,7 +5845,7 @@ impl AccountsDb { let accounts = storage.all_accounts(); accounts.into_iter().for_each(|stored_account| { let this_version = stored_account.meta.write_version; - match accounts_map.entry(&stored_account.meta.pubkey) { + match accounts_map.entry(stored_account.meta.pubkey) { std::collections::hash_map::Entry::Vacant(entry) => { entry.insert((this_version, storage.append_vec_id(), stored_account)); } @@ -5872,14 +5872,25 @@ impl AccountsDb { return 0; } + let secondary = !self.account_indexes.is_empty(); + let len = accounts_map.len(); let items = accounts_map - .iter() + .into_iter() .map(|(pubkey, (_, store_id, stored_account))| { + if secondary { + self.accounts_index.update_secondary_indexes( + &pubkey, + &stored_account.account_meta.owner, + stored_account.data, + &self.account_indexes, + ); + } + ( - *pubkey, + pubkey, AccountInfo { - store_id: *store_id, + store_id, offset: stored_account.offset, stored_size: stored_account.stored_size, lamports: stored_account.account_meta.lamports, @@ -5897,17 +5908,6 @@ impl AccountsDb { if !dirty_pubkeys.is_empty() { self.uncleaned_pubkeys.insert(*slot, dirty_pubkeys); } - - if !self.account_indexes.is_empty() { - for (pubkey, (_, _store_id, stored_account)) in accounts_map.iter() { - self.accounts_index.update_secondary_indexes( - pubkey, - &stored_account.account_meta.owner, - stored_account.data, - &self.account_indexes, - ); - } - } insert_us } diff --git a/runtime/src/accounts_index.rs b/runtime/src/accounts_index.rs index ee33c58c8f..3f22845c37 100644 --- a/runtime/src/accounts_index.rs +++ b/runtime/src/accounts_index.rs @@ -1376,11 +1376,11 @@ impl( - &'a self, + pub(crate) fn insert_new_if_missing_into_primary_index( + &self, slot: Slot, item_len: usize, - items: impl Iterator, + items: impl Iterator, ) -> (Vec, u64) { let expected_items_per_bin = item_len * 2 / BINS; // big enough so not likely to re-allocate, small enough to not over-allocate let mut binned = (0..BINS) @@ -1388,10 +1388,10 @@ impl>(); items.for_each(|(pubkey, account_info)| { - let bin = get_bin_pubkey(pubkey); + let bin = get_bin_pubkey(&pubkey); // this value is equivalent to what update() below would have created if we inserted a new item let info = WriteAccountMapEntry::new_entry_after_update(slot, account_info); - binned[bin].1.push((*pubkey, info)); + binned[bin].1.push((pubkey, info)); }); binned.retain(|x| !x.1.is_empty()); @@ -2550,7 +2550,7 @@ pub mod tests { let index = AccountsIndex::::default(); let account_info = true; - let items = vec![(pubkey, account_info)]; + let items = vec![(*pubkey, account_info)]; index.insert_new_if_missing_into_primary_index(slot, items.len(), items.into_iter()); let mut ancestors = Ancestors::default(); @@ -2569,7 +2569,7 @@ pub mod tests { // not zero lamports let index = AccountsIndex::::default(); let account_info: AccountInfoTest = 0 as AccountInfoTest; - let items = vec![(pubkey, account_info)]; + let items = vec![(*pubkey, account_info)]; index.insert_new_if_missing_into_primary_index(slot, items.len(), items.into_iter()); let mut ancestors = Ancestors::default(); @@ -2621,7 +2621,7 @@ pub mod tests { let index = AccountsIndex::::default(); let account_infos = [true, false]; - let items = vec![(&key0, account_infos[0]), (&key1, account_infos[1])]; + let items = vec![(key0, account_infos[0]), (key1, account_infos[1])]; index.insert_new_if_missing_into_primary_index(slot0, items.len(), items.into_iter()); for (i, key) in [key0, key1].iter().enumerate() { @@ -2664,7 +2664,7 @@ pub mod tests { &mut gc, ); } else { - let items = vec![(&key, account_infos[0].clone())]; + let items = vec![(key, account_infos[0].clone())]; index.insert_new_if_missing_into_primary_index(slot0, items.len(), items.into_iter()); } assert!(gc.is_empty()); @@ -2698,7 +2698,7 @@ pub mod tests { &mut gc, ); } else { - let items = vec![(&key, account_infos[1].clone())]; + let items = vec![(key, account_infos[1].clone())]; index.insert_new_if_missing_into_primary_index(slot1, items.len(), items.into_iter()); } assert!(gc.is_empty());