create remove_if_slot_list_empty to define accounts index behavior (#19581)
This commit is contained in:
parent
0571962776
commit
2874f6b0a2
|
@ -1233,10 +1233,7 @@ impl<T: IsCached> AccountsIndex<T> {
|
|||
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();
|
||||
|
||||
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
|
||||
|
@ -1245,6 +1242,21 @@ impl<T: IsCached> AccountsIndex<T> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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<T>,
|
||||
) -> 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
|
||||
|
|
Loading…
Reference in New Issue