Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create remove_if_slot_list_empty to define accounts index behavior #19581

Merged
merged 1 commit into from
Sep 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions runtime/src/accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1233,20 +1233,32 @@ 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();

// 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<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,
Expand Down