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) {
 | 
			
		||||
        if !accounts_map.is_empty() {
 | 
			
		||||
            let len = accounts_map.len();
 | 
			
		||||
 | 
			
		||||
            let mut items = Vec::with_capacity(len);
 | 
			
		||||
            let mut dirty_pubkeys = accounts_map
 | 
			
		||||
            let items = accounts_map
 | 
			
		||||
                .iter()
 | 
			
		||||
                .map(|(pubkey, (_, store_id, stored_account))| {
 | 
			
		||||
                    items.push((
 | 
			
		||||
                    (
 | 
			
		||||
                        pubkey,
 | 
			
		||||
                        AccountInfo {
 | 
			
		||||
                            store_id: *store_id,
 | 
			
		||||
@@ -5886,25 +5883,17 @@ impl AccountsDb {
 | 
			
		||||
                            stored_size: stored_account.stored_size,
 | 
			
		||||
                            lamports: stored_account.account_meta.lamports,
 | 
			
		||||
                        },
 | 
			
		||||
                    ));
 | 
			
		||||
                    *pubkey
 | 
			
		||||
                    )
 | 
			
		||||
                })
 | 
			
		||||
                .collect::<Vec<_>>();
 | 
			
		||||
 | 
			
		||||
            let items_len = items.len();
 | 
			
		||||
            let dirty_pubkey_mask = self
 | 
			
		||||
            let dirty_pubkeys = self
 | 
			
		||||
                .accounts_index
 | 
			
		||||
                .insert_new_if_missing_into_primary_index(*slot, items);
 | 
			
		||||
 | 
			
		||||
            assert_eq!(dirty_pubkey_mask.len(), items_len);
 | 
			
		||||
 | 
			
		||||
            let mut dirty_pubkey_mask_iter = dirty_pubkey_mask.iter();
 | 
			
		||||
 | 
			
		||||
            // dirty_pubkey_mask will return true if an item has multiple rooted entries for
 | 
			
		||||
            // dirty_pubkeys will contain a pubkey if an item has multiple rooted entries for
 | 
			
		||||
            // 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
 | 
			
		||||
            // pubkeys with multiple updates.
 | 
			
		||||
            dirty_pubkeys.retain(|_k| *dirty_pubkey_mask_iter.next().unwrap());
 | 
			
		||||
            // be done on that pubkey. Use only those pubkeys with multiple updates.
 | 
			
		||||
            if !dirty_pubkeys.is_empty() {
 | 
			
		||||
                self.uncleaned_pubkeys.insert(*slot, dirty_pubkeys);
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -1357,7 +1357,8 @@ impl<T: 'static + Clone + IsCached + ZeroLamport> AccountsIndex<T> {
 | 
			
		||||
        &self,
 | 
			
		||||
        slot: Slot,
 | 
			
		||||
        items: Vec<(&Pubkey, T)>,
 | 
			
		||||
    ) -> Vec<bool> {
 | 
			
		||||
    ) -> Vec<Pubkey> {
 | 
			
		||||
        let item_len = items.len();
 | 
			
		||||
        let potentially_new_items = items
 | 
			
		||||
            .iter()
 | 
			
		||||
            .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
 | 
			
		||||
 | 
			
		||||
        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();
 | 
			
		||||
        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(
 | 
			
		||||
                    pubkey,
 | 
			
		||||
                    &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 {
 | 
			
		||||
                    w_account_entry.update(slot, account_info, &mut _reclaims);
 | 
			
		||||
                    true
 | 
			
		||||
                } else {
 | 
			
		||||
                    false
 | 
			
		||||
                    duplicate_keys.push(*pubkey);
 | 
			
		||||
                }
 | 
			
		||||
            })
 | 
			
		||||
            .collect()
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
        duplicate_keys
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Updates the given pubkey at the given slot with the new account information.
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user