From f2e3e39a7c04187beb0b2f5e64360439fa880c08 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Tue, 3 Dec 2024 10:42:22 +1100 Subject: [PATCH] AccountsDb: make write_accounts_to_cache() never block sending to the 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. --- accounts-db/src/accounts_db.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index d062135f996f7f..850b04495d21d8 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -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}, @@ -2344,7 +2344,7 @@ impl AccountsDb { fn background_hasher(receiver: Receiver>) { info!("Background account hasher has started"); loop { - let result = receiver.recv(); + let result = receiver.try_recv(); match result { Ok(accounts) => { for account in accounts { @@ -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; }