rework dirty_pubkeys from insert_new_if_missing_into_primary_index (#18200)
This commit is contained in:
committed by
GitHub
parent
db3475bcdf
commit
4b314be5bd
@ -5872,13 +5872,10 @@ impl AccountsDb {
|
|||||||
|
|
||||||
fn generate_index_for_slot<'a>(&self, accounts_map: GenerateIndexAccountsMap<'a>, slot: &Slot) {
|
fn generate_index_for_slot<'a>(&self, accounts_map: GenerateIndexAccountsMap<'a>, slot: &Slot) {
|
||||||
if !accounts_map.is_empty() {
|
if !accounts_map.is_empty() {
|
||||||
let len = accounts_map.len();
|
let items = accounts_map
|
||||||
|
|
||||||
let mut items = Vec::with_capacity(len);
|
|
||||||
let mut dirty_pubkeys = accounts_map
|
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(pubkey, (_, store_id, stored_account))| {
|
.map(|(pubkey, (_, store_id, stored_account))| {
|
||||||
items.push((
|
(
|
||||||
pubkey,
|
pubkey,
|
||||||
AccountInfo {
|
AccountInfo {
|
||||||
store_id: *store_id,
|
store_id: *store_id,
|
||||||
@ -5886,25 +5883,17 @@ impl AccountsDb {
|
|||||||
stored_size: stored_account.stored_size,
|
stored_size: stored_account.stored_size,
|
||||||
lamports: stored_account.account_meta.lamports,
|
lamports: stored_account.account_meta.lamports,
|
||||||
},
|
},
|
||||||
));
|
)
|
||||||
*pubkey
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let items_len = items.len();
|
let dirty_pubkeys = self
|
||||||
let dirty_pubkey_mask = self
|
|
||||||
.accounts_index
|
.accounts_index
|
||||||
.insert_new_if_missing_into_primary_index(*slot, items);
|
.insert_new_if_missing_into_primary_index(*slot, items);
|
||||||
|
|
||||||
assert_eq!(dirty_pubkey_mask.len(), items_len);
|
// dirty_pubkeys will contain a pubkey if an item has multiple rooted entries for
|
||||||
|
|
||||||
let mut dirty_pubkey_mask_iter = dirty_pubkey_mask.iter();
|
|
||||||
|
|
||||||
// dirty_pubkey_mask will return true if an item has multiple rooted entries for
|
|
||||||
// a given pubkey. If there is just a single item, there is no cleaning to
|
// a given pubkey. If there is just a single item, there is no cleaning to
|
||||||
// be done on that pubkey. Prune the touched pubkey set here for only those
|
// be done on that pubkey. Use only those pubkeys with multiple updates.
|
||||||
// pubkeys with multiple updates.
|
|
||||||
dirty_pubkeys.retain(|_k| *dirty_pubkey_mask_iter.next().unwrap());
|
|
||||||
if !dirty_pubkeys.is_empty() {
|
if !dirty_pubkeys.is_empty() {
|
||||||
self.uncleaned_pubkeys.insert(*slot, dirty_pubkeys);
|
self.uncleaned_pubkeys.insert(*slot, dirty_pubkeys);
|
||||||
}
|
}
|
||||||
|
@ -1357,7 +1357,8 @@ impl<T: 'static + Clone + IsCached + ZeroLamport> AccountsIndex<T> {
|
|||||||
&self,
|
&self,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
items: Vec<(&Pubkey, T)>,
|
items: Vec<(&Pubkey, T)>,
|
||||||
) -> Vec<bool> {
|
) -> Vec<Pubkey> {
|
||||||
|
let item_len = items.len();
|
||||||
let potentially_new_items = items
|
let potentially_new_items = items
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(_pubkey, account_info)| {
|
.map(|(_pubkey, account_info)| {
|
||||||
@ -1367,12 +1368,12 @@ impl<T: 'static + Clone + IsCached + ZeroLamport> AccountsIndex<T> {
|
|||||||
.collect::<Vec<_>>(); // collect here so we have created all data prior to obtaining lock
|
.collect::<Vec<_>>(); // collect here so we have created all data prior to obtaining lock
|
||||||
|
|
||||||
let mut _reclaims = SlotList::new();
|
let mut _reclaims = SlotList::new();
|
||||||
|
let mut duplicate_keys = Vec::with_capacity(item_len / 100); // just an estimate
|
||||||
let mut w_account_maps = self.get_account_maps_write_lock();
|
let mut w_account_maps = self.get_account_maps_write_lock();
|
||||||
items
|
items
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.zip(potentially_new_items.into_iter())
|
.zip(potentially_new_items.into_iter())
|
||||||
.map(|((pubkey, account_info), new_item)| {
|
.for_each(|((pubkey, account_info), new_item)| {
|
||||||
let account_entry = self.insert_new_entry_if_missing_with_lock(
|
let account_entry = self.insert_new_entry_if_missing_with_lock(
|
||||||
pubkey,
|
pubkey,
|
||||||
&mut w_account_maps,
|
&mut w_account_maps,
|
||||||
@ -1380,12 +1381,11 @@ impl<T: 'static + Clone + IsCached + ZeroLamport> AccountsIndex<T> {
|
|||||||
);
|
);
|
||||||
if let Some(mut w_account_entry) = account_entry {
|
if let Some(mut w_account_entry) = account_entry {
|
||||||
w_account_entry.update(slot, account_info, &mut _reclaims);
|
w_account_entry.update(slot, account_info, &mut _reclaims);
|
||||||
true
|
duplicate_keys.push(*pubkey);
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
.collect()
|
|
||||||
|
duplicate_keys
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates the given pubkey at the given slot with the new account information.
|
// Updates the given pubkey at the given slot with the new account information.
|
||||||
|
Reference in New Issue
Block a user