accounts index stats (#19797)

This commit is contained in:
Jeff Washington (jwash)
2021-09-12 17:14:59 -05:00
committed by GitHub
parent ab152f1319
commit 3617d43e76
6 changed files with 208 additions and 8 deletions

View File

@@ -1,4 +1,5 @@
use crate::{
accounts_index_storage::AccountsIndexStorage,
ancestors::Ancestors,
contains::Contains,
in_mem_accounts_index::InMemAccountsIndex,
@@ -799,6 +800,8 @@ pub struct AccountsIndex<T: IsCached> {
// on any of these slots fails. This is safe to purge once the associated Bank is dropped and
// scanning the fork with that Bank at the tip is no longer possible.
pub removed_bank_ids: Mutex<HashSet<BankId>>,
storage: AccountsIndexStorage,
}
impl<T: IsCached> AccountsIndex<T> {
@@ -807,7 +810,7 @@ impl<T: IsCached> AccountsIndex<T> {
}
pub fn new(config: Option<AccountsIndexConfig>) -> Self {
let (account_maps, bin_calculator) = Self::allocate_accounts_index(config);
let (account_maps, bin_calculator, storage) = Self::allocate_accounts_index(config);
Self {
account_maps,
bin_calculator,
@@ -823,22 +826,24 @@ impl<T: IsCached> AccountsIndex<T> {
roots_tracker: RwLock::<RootsTracker>::default(),
ongoing_scan_roots: RwLock::<BTreeMap<Slot, u64>>::default(),
removed_bank_ids: Mutex::<HashSet<BankId>>::default(),
storage,
}
}
fn allocate_accounts_index(
config: Option<AccountsIndexConfig>,
) -> (LockMapType<T>, PubkeyBinCalculator16) {
) -> (LockMapType<T>, PubkeyBinCalculator16, AccountsIndexStorage) {
let bins = config
.and_then(|config| config.bins)
.unwrap_or(BINS_DEFAULT);
// create bin_calculator early to verify # bins is reasonable
let bin_calculator = PubkeyBinCalculator16::new(bins);
let storage = AccountsIndexStorage::new();
let account_maps = (0..bins)
.into_iter()
.map(|_bin| RwLock::new(AccountMap::new()))
.map(|_bin| RwLock::new(AccountMap::new(&storage)))
.collect::<Vec<_>>();
(account_maps, bin_calculator)
(account_maps, bin_calculator, storage)
}
fn iter<R>(&self, range: Option<&R>, collect_all_unsorted: bool) -> AccountsIndexIterator<T>