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.

(cherry picked from commit f2e3e39)
  • Loading branch information
alessandrod authored and mergify[bot] committed Dec 2, 2024
1 parent d07fc9b commit 7be2171
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 @@ -72,7 +72,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 @@ -2260,7 +2260,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 @@ -2271,7 +2271,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 7be2171

Please sign in to comment.