Fixes race in RwLockSecondaryIndexEntry::insert_if_not_exists() (#815)

This commit is contained in:
Brooks 2024-04-15 14:52:20 -04:00 committed by GitHub
parent 657e032ac0
commit 9ba0d6fabb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 5 deletions

View File

@ -74,12 +74,15 @@ pub struct RwLockSecondaryIndexEntry {
impl SecondaryIndexEntry for RwLockSecondaryIndexEntry {
fn insert_if_not_exists(&self, key: &Pubkey, inner_keys_count: &AtomicU64) {
let exists = self.account_keys.read().unwrap().contains(key);
if !exists {
let mut w_account_keys = self.account_keys.write().unwrap();
w_account_keys.insert(*key);
if self.account_keys.read().unwrap().contains(key) {
// the key already exists, so nothing to do here
return;
}
let was_newly_inserted = self.account_keys.write().unwrap().insert(*key);
if was_newly_inserted {
inner_keys_count.fetch_add(1, Ordering::Relaxed);
};
}
}
fn remove_inner_key(&self, key: &Pubkey) -> bool {