Skip to content

Commit

Permalink
Avoid acquiring read lock twice in same thread
Browse files Browse the repository at this point in the history
  • Loading branch information
dmakarov committed Jul 31, 2024
1 parent 8e8d710 commit 5eaab3c
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ use {
path::{Path, PathBuf},
sync::{
atomic::{AtomicBool, AtomicU32, AtomicU64, AtomicUsize, Ordering},
Arc, Condvar, Mutex, RwLock,
Arc, Condvar, Mutex, RwLock, RwLockReadGuard,
},
thread::{sleep, Builder},
time::{Duration, Instant},
Expand Down Expand Up @@ -2764,7 +2764,7 @@ impl AccountsDb {
// do not match the criteria of deleting all appendvecs which contain them
// then increment their storage count.
let mut already_counted = IntSet::default();
for bin in purges {
for (bin_index, bin) in purges.iter().enumerate() {
let bin = bin.read().unwrap();
for (
pubkey,
Expand Down Expand Up @@ -2843,11 +2843,18 @@ impl AccountsDb {
for key in affected_pubkeys {
let purges_bin_index =
self.accounts_index.bin_calculator.bin_from_pubkey(key);
let bin = purges[purges_bin_index].read().unwrap();
for (slot, _account_info) in &bin.get(key).unwrap().slot_list {
if !already_counted.contains(slot) {
pending_stores.insert(*slot);
}
let mut update_pending_stores =
|bin: &RwLockReadGuard<HashMap<Pubkey, CleaningInfo>>| {
for (slot, _account_info) in &bin.get(key).unwrap().slot_list {
if !already_counted.contains(slot) {
pending_stores.insert(*slot);
}
}
};
if purges_bin_index == bin_index {
update_pending_stores(&bin);
} else {
update_pending_stores(&purges[purges_bin_index].read().unwrap());
}
}
}
Expand Down

0 comments on commit 5eaab3c

Please sign in to comment.