From 8cc6f581f19f7c4d48d21cfc0d4d9dde84e9b024 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Thu, 2 Sep 2021 13:26:19 -0500 Subject: [PATCH] create remove_if_slot_list_empty to define accounts index behavior --- runtime/src/accounts_index.rs | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/runtime/src/accounts_index.rs b/runtime/src/accounts_index.rs index 782944eaf1a37b..312e059ad30ebb 100644 --- a/runtime/src/accounts_index.rs +++ b/runtime/src/accounts_index.rs @@ -1233,20 +1233,32 @@ impl AccountsIndex { if !dead_keys.is_empty() { for key in dead_keys.iter() { let mut w_index = self.get_account_maps_write_lock(key); - if let Entry::Occupied(index_entry) = w_index.entry(**key) { - if index_entry.get().slot_list.read().unwrap().is_empty() { - index_entry.remove(); - - // Note it's only safe to remove all the entries for this key - // because we have the lock for this key's entry in the AccountsIndex, - // so no other thread is also updating the index - self.purge_secondary_indexes_by_inner_key(key, account_indexes); - } + if self.remove_if_slot_list_empty(key, &mut w_index) { + // Note it's only safe to remove all the entries for this key + // because we have the lock for this key's entry in the AccountsIndex, + // so no other thread is also updating the index + self.purge_secondary_indexes_by_inner_key(key, account_indexes); } } } } + // If the slot list for pubkey exists in the index and is empty, remove the index entry for pubkey and return true. + // Return false otherwise. + fn remove_if_slot_list_empty( + &self, + pubkey: &Pubkey, + lock: &mut AccountMapsWriteLock, + ) -> bool { + if let Entry::Occupied(index_entry) = lock.entry(*pubkey) { + if index_entry.get().slot_list.read().unwrap().is_empty() { + index_entry.remove(); + return true; + } + } + false + } + /// call func with every pubkey and index visible from a given set of ancestors pub(crate) fn scan_accounts( &self,