diff --git a/runtime/src/accounts_index.rs b/runtime/src/accounts_index.rs index ba38f700c8..d5175f4aec 100644 --- a/runtime/src/accounts_index.rs +++ b/runtime/src/accounts_index.rs @@ -745,7 +745,7 @@ impl AccountsIndex { let storage = AccountsIndexStorage::new(bins); let account_maps = (0..bins) .into_iter() - .map(|bin| RwLock::new(Arc::new(InMemAccountsIndex::new(&storage, bin)))) + .map(|bin| RwLock::new(Arc::clone(&storage.in_mem[bin]))) .collect::>(); (account_maps, bin_calculator, storage) } diff --git a/runtime/src/accounts_index_storage.rs b/runtime/src/accounts_index_storage.rs index 5adcb3f29d..fe61b3947a 100644 --- a/runtime/src/accounts_index_storage.rs +++ b/runtime/src/accounts_index_storage.rs @@ -1,5 +1,6 @@ use crate::accounts_index::IndexValue; use crate::bucket_map_holder::BucketMapHolder; +use crate::in_mem_accounts_index::InMemAccountsIndex; use crate::waitable_condvar::WaitableCondvar; use std::fmt::Debug; use std::{ @@ -22,6 +23,7 @@ pub struct AccountsIndexStorage { // eventually the backing storage storage: Arc>, + pub in_mem: Vec>>, } impl Debug for AccountsIndexStorage { @@ -43,6 +45,12 @@ impl Drop for AccountsIndexStorage { impl AccountsIndexStorage { pub fn new(bins: usize) -> AccountsIndexStorage { let storage = Arc::new(BucketMapHolder::new(bins)); + + let in_mem = (0..bins) + .into_iter() + .map(|bin| Arc::new(InMemAccountsIndex::new(&storage, bin))) + .collect(); + let storage_ = storage.clone(); let exit = Arc::new(AtomicBool::default()); let exit_ = exit.clone(); @@ -62,6 +70,7 @@ impl AccountsIndexStorage { wait, handle, storage, + in_mem, } } diff --git a/runtime/src/bucket_map_holder.rs b/runtime/src/bucket_map_holder.rs index eaf9c00bd2..e1cd0ee6f6 100644 --- a/runtime/src/bucket_map_holder.rs +++ b/runtime/src/bucket_map_holder.rs @@ -25,7 +25,6 @@ impl BucketMapHolder { _phantom: std::marker::PhantomData::::default(), } } - // intended to execute in a bg thread pub fn background(&self, exit: Arc, wait: Arc) { loop { diff --git a/runtime/src/in_mem_accounts_index.rs b/runtime/src/in_mem_accounts_index.rs index 3a652da5a3..1c86be2f24 100644 --- a/runtime/src/in_mem_accounts_index.rs +++ b/runtime/src/in_mem_accounts_index.rs @@ -1,7 +1,6 @@ use crate::accounts_index::{ AccountMapEntry, AccountMapEntryInner, IndexValue, SlotList, WriteAccountMapEntry, }; -use crate::accounts_index_storage::AccountsIndexStorage; use crate::bucket_map_holder::BucketMapHolder; use crate::bucket_map_holder_stats::BucketMapHolderStats; use solana_measure::measure::Measure; @@ -29,10 +28,10 @@ impl Debug for InMemAccountsIndex { } impl InMemAccountsIndex { - pub fn new(storage: &AccountsIndexStorage, bin: usize) -> Self { + pub fn new(storage: &Arc>, bin: usize) -> Self { Self { map_internal: RwLock::default(), - storage: storage.storage().clone(), + storage: Arc::clone(storage), bin, } }