move remove_if_slot_list_empty to InMemAccountsIndex (#19801)

This commit is contained in:
Jeff Washington (jwash) 2021-09-12 10:26:04 -05:00 committed by GitHub
parent 361101bd31
commit a295febf04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 17 deletions

View File

@ -1234,7 +1234,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 self.remove_if_slot_list_empty(key, &mut w_index) {
if w_index.remove_if_slot_list_empty(**key) {
// 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
@ -1244,22 +1244,6 @@ 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
pub(crate) fn scan_accounts<F>(
&self,

View File

@ -42,6 +42,18 @@ impl<T: IsCached> InMemAccountsIndex<T> {
self.map.remove(key);
}
// 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.
pub fn remove_if_slot_list_empty(&mut self, pubkey: Pubkey) -> bool {
if let Entry::Occupied(index_entry) = self.map.entry(pubkey) {
if index_entry.get().slot_list.read().unwrap().is_empty() {
index_entry.remove();
return true;
}
}
false
}
pub fn len(&self) -> usize {
self.map.len()
}