Skip to content

Commit

Permalink
Removes background account hasher
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo committed Feb 7, 2025
1 parent 1baa403 commit 140ea89
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
25 changes: 18 additions & 7 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,7 @@ pub struct AccountsDb {

write_cache_limit_bytes: Option<u64>,

sender_bg_hasher: Option<Sender<Vec<CachedAccount>>>,
sender_bg_hasher: RwLock<Option<Sender<Vec<CachedAccount>>>>,
read_only_accounts_cache: ReadOnlyAccountsCache,

/// distribute the accounts across storage lists
Expand Down Expand Up @@ -2014,7 +2014,7 @@ impl AccountsDb {

let thread_pool_hash = make_hash_thread_pool(accounts_db_config.num_hash_threads);

let mut new = Self {
let new = Self {
accounts_index,
paths,
base_working_path,
Expand Down Expand Up @@ -2066,7 +2066,7 @@ impl AccountsDb {
active_stats: ActiveStats::default(),
storage: AccountStorage::default(),
accounts_cache: AccountsCache::default(),
sender_bg_hasher: None,
sender_bg_hasher: RwLock::new(None),
uncleaned_pubkeys: DashMap::default(),
next_id: AtomicAccountsFileId::new(0),
shrink_candidate_slots: Mutex::new(ShrinkCandidates::default()),
Expand Down Expand Up @@ -2095,7 +2095,6 @@ impl AccountsDb {
best_ancient_slots_to_shrink: RwLock::default(),
};

new.start_background_hasher();
{
for path in new.paths.iter() {
std::fs::create_dir_all(path).expect("Create directory failed.");
Expand Down Expand Up @@ -2369,15 +2368,27 @@ impl AccountsDb {
info!("Background account hasher has stopped");
}

fn start_background_hasher(&mut self) {
pub fn start_background_hasher(&self) {
if self.is_background_hasher_running() {
return;
}

let (sender, receiver) = unbounded();
Builder::new()
.name("solDbStoreHashr".to_string())
.spawn(move || {
Self::background_hasher(receiver);
})
.unwrap();
self.sender_bg_hasher = Some(sender);
*self.sender_bg_hasher.write().unwrap() = Some(sender);
}

pub fn stop_background_hasher(&self) {
drop(self.sender_bg_hasher.write().unwrap().take())
}

pub fn is_background_hasher_running(&self) -> bool {
self.sender_bg_hasher.read().unwrap().is_some()
}

#[must_use]
Expand Down Expand Up @@ -6528,7 +6539,7 @@ impl AccountsDb {
.unzip();

// hash this accounts in bg
if let Some(ref sender) = &self.sender_bg_hasher {
if let Some(sender) = self.sender_bg_hasher.read().unwrap().as_ref() {
let _ = sender.send(cached_accounts);
};

Expand Down
14 changes: 14 additions & 0 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4868,6 +4868,14 @@ impl Bank {
);
}

// If the accounts delta hash is still in use, start the background account hasher
if !self
.feature_set
.is_active(&feature_set::remove_accounts_delta_hash::id())
{
self.rc.accounts.accounts_db.start_background_hasher();
}

if !debug_do_not_add_builtins {
for builtin in BUILTINS
.iter()
Expand Down Expand Up @@ -6540,6 +6548,12 @@ impl Bank {
vote_cost_limit,
);
}

if new_feature_activations.contains(&feature_set::remove_accounts_delta_hash::id()) {
// If the accounts delta hash has been removed, then we no longer need to compute the
// AccountHash for modified accounts, and can stop the background account hasher.
self.rc.accounts.accounts_db.stop_background_hasher();
}
}

fn apply_updated_hashes_per_tick(&mut self, hashes_per_tick: u64) {
Expand Down

0 comments on commit 140ea89

Please sign in to comment.