Skip to content

Commit

Permalink
AccountsDb: make write_accounts_to_cache() never block sending to the…
Browse files Browse the repository at this point in the history
… bg hasher (#3814)

Avoid commit_transactions() => store() => store_accounts_to() callers
having to notify the bg hasher thread by doing an explicit sleep instead
of sleeping on channel.recv() when the channel is empty. This avoids the
case in which multiple replay/banking threads call commit_transactions()
at the same time and end up... sleeping themselves acquiring the mutex
to wake up the bg hasher.
  • Loading branch information
alessandrod authored Dec 2, 2024
1 parent 1258701 commit f2e3e39
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ use {
u64_align, utils,
verify_accounts_hash_in_background::VerifyAccountsHashInBackground,
},
crossbeam_channel::{unbounded, Receiver, Sender},
crossbeam_channel::{unbounded, Receiver, Sender, TryRecvError},
dashmap::{DashMap, DashSet},
log::*,
rand::{thread_rng, Rng},
Expand Down Expand Up @@ -2344,7 +2344,7 @@ impl AccountsDb {
fn background_hasher(receiver: Receiver<Vec<CachedAccount>>) {
info!("Background account hasher has started");
loop {
let result = receiver.recv();
let result = receiver.try_recv();
match result {
Ok(accounts) => {
for account in accounts {
Expand All @@ -2355,7 +2355,10 @@ impl AccountsDb {
};
}
}
Err(err) => {
Err(TryRecvError::Empty) => {
sleep(Duration::from_millis(5));
}
Err(err @ TryRecvError::Disconnected) => {
info!("Background account hasher is stopping because: {err}");
break;
}
Expand Down

0 comments on commit f2e3e39

Please sign in to comment.