Skip to content

Commit

Permalink
pr: fix a race
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoranYi committed Dec 12, 2024
1 parent 819f026 commit ef3e873
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion accounts-db/src/accounts_index/in_mem_accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,13 +769,25 @@ impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> InMemAccountsIndex<T,
}
drop(slot_list);

InMemAccountsIndex::<T, U>::lock_and_update_slot_list(
let updated_slot_list_len = InMemAccountsIndex::<T, U>::lock_and_update_slot_list(
occupied.get(),
(slot, account_info),
None, // should be None because we don't expect a different slot # during index generation
&mut Vec::default(),
UpsertReclaim::IgnoreReclaims,
);

// In case of a race condition, multiple threads try to insert
// to the same pubkey with different slots. We only need to
// record `other_slot` once. If the slot list length after
// update is not 2, it means that someone else has already
// recorded `other_slot` before us. Therefore, We don't need to
// record it again.
if updated_slot_list_len != 2 {
// clear `other_slot` if we don't win the race.
other_slot = None;
}

(
true, /* found in mem */
true, /* already existed */
Expand Down

0 comments on commit ef3e873

Please sign in to comment.