Skip to content

Commit

Permalink
Checks ref count and slot list again before flushing index entry (sol…
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored Aug 23, 2024
1 parent fc84a52 commit 2bdabfa
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 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 @@ -1255,14 +1255,24 @@ impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> InMemAccountsIndex<T,
let slot_list = slot_list
.take()
.unwrap_or_else(|| v.slot_list.read().unwrap());
// Check the ref count and slot list one more time before flushing.
// It is possible the foreground has updated this entry since
// we last checked above in `should_evict_from_mem()`.
// If the entry *was* updated, re-mark it as dirty then
// skip to the next pubkey/entry.
let ref_count = v.ref_count();
if ref_count != 1 || slot_list.len() != 1 {
v.set_dirty(true);
break;
}
disk.try_write(
&k,
(
&slot_list
.iter()
.map(|(slot, info)| (*slot, (*info).into()))
.collect::<Vec<_>>(),
v.ref_count(),
ref_count,
),
)
};
Expand Down

0 comments on commit 2bdabfa

Please sign in to comment.