Use option for account index bucket parameter (#19150)

This commit is contained in:
Jeff Washington (jwash) 2021-08-10 11:32:25 -05:00 committed by GitHub
parent 8557dac51d
commit 651343688d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 33 additions and 32 deletions

View File

@ -191,7 +191,7 @@ mod tests {
check_hash_calculation,
false,
false,
solana_runtime::accounts_index::BINS_FOR_TESTING,
Some(solana_runtime::accounts_index::BINS_FOR_TESTING),
)
.unwrap();
@ -808,7 +808,7 @@ mod tests {
false,
false,
false,
solana_runtime::accounts_index::BINS_FOR_TESTING,
Some(solana_runtime::accounts_index::BINS_FOR_TESTING),
)?;
assert_eq!(bank, &deserialized_bank);

View File

@ -132,7 +132,7 @@ fn load_from_snapshot(
process_options.accounts_db_test_hash_calculation,
process_options.accounts_db_skip_shrink,
process_options.verify_index,
solana_runtime::accounts_index::BINS_DEFAULT,
None,
)
.expect("Load from snapshot failed");

View File

@ -416,7 +416,7 @@ pub fn process_blockstore(
opts.accounts_db_caching_enabled,
opts.shrink_ratio,
false,
solana_runtime::accounts_index::BINS_DEFAULT,
None, // later, this will be passed from ProcessOptions
);
let bank0 = Arc::new(bank0);
info!("processing ledger for slot 0...");

View File

@ -127,7 +127,7 @@ fn initialize_from_snapshot(
process_options.accounts_db_test_hash_calculation,
false,
process_options.verify_index,
solana_runtime::accounts_index::BINS_DEFAULT,
None,
)
.unwrap();

View File

@ -5,7 +5,7 @@ extern crate test;
use rand::{thread_rng, Rng};
use solana_runtime::{
accounts_db::AccountInfo,
accounts_index::{AccountSecondaryIndexes, AccountsIndex, BINS_DEFAULT},
accounts_index::{AccountSecondaryIndexes, AccountsIndex, BINS_FOR_BENCHMARKS},
};
use solana_sdk::pubkey::{self, Pubkey};
use test::Bencher;
@ -18,7 +18,7 @@ fn bench_accounts_index(bencher: &mut Bencher) {
const NUM_FORKS: u64 = 16;
let mut reclaims = vec![];
let index = AccountsIndex::<AccountInfo>::new(BINS_DEFAULT);
let index = AccountsIndex::<AccountInfo>::new(Some(BINS_FOR_BENCHMARKS));
for f in 0..NUM_FORKS {
for pubkey in pubkeys.iter().take(NUM_PUBKEYS) {
index.upsert(

View File

@ -139,7 +139,7 @@ impl Accounts {
account_indexes,
caching_enabled,
shrink_ratio,
BINS_FOR_TESTING,
Some(BINS_FOR_TESTING),
)
}
@ -156,7 +156,7 @@ impl Accounts {
account_indexes,
caching_enabled,
shrink_ratio,
BINS_FOR_BENCHMARKS,
Some(BINS_FOR_BENCHMARKS),
)
}
@ -166,7 +166,7 @@ impl Accounts {
account_indexes: AccountSecondaryIndexes,
caching_enabled: bool,
shrink_ratio: AccountShrinkThreshold,
accounts_index_bins: usize,
accounts_index_bins: Option<usize>,
) -> Self {
Self {
accounts_db: Arc::new(AccountsDb::new_with_config(

View File

@ -1420,7 +1420,7 @@ impl AccountsDb {
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
BINS_FOR_TESTING,
Some(BINS_FOR_TESTING),
)
}
@ -1430,7 +1430,7 @@ impl AccountsDb {
account_indexes: AccountSecondaryIndexes,
caching_enabled: bool,
shrink_ratio: AccountShrinkThreshold,
accounts_index_bins: usize,
accounts_index_bins: Option<usize>,
) -> Self {
let accounts_index = AccountsIndex::new(accounts_index_bins);
let mut new = if !paths.is_empty() {
@ -6227,7 +6227,7 @@ impl AccountsDb {
account_indexes,
caching_enabled,
shrink_ratio,
BINS_FOR_TESTING,
Some(BINS_FOR_TESTING),
)
}

View File

@ -761,10 +761,10 @@ pub struct AccountsIndex<T> {
impl<T: IsCached> AccountsIndex<T> {
pub fn default_for_tests() -> Self {
Self::new(BINS_FOR_TESTING)
Self::new(Some(BINS_FOR_TESTING))
}
pub fn new(bins: usize) -> Self {
pub fn new(bins: Option<usize>) -> Self {
let (account_maps, bin_calculator) = Self::allocate_accounts_index(bins);
Self {
account_maps,
@ -784,7 +784,8 @@ impl<T: IsCached> AccountsIndex<T> {
}
}
fn allocate_accounts_index(bins: usize) -> (LockMapType<T>, PubkeyBinCalculator16) {
fn allocate_accounts_index(bins: Option<usize>) -> (LockMapType<T>, PubkeyBinCalculator16) {
let bins = bins.unwrap_or(BINS_DEFAULT);
let account_maps = (0..bins)
.into_iter()
.map(|_| RwLock::new(AccountMap::default()))
@ -4023,6 +4024,6 @@ pub mod tests {
#[test]
#[should_panic(expected = "bins.is_power_of_two()")]
fn test_illegal_bins() {
AccountsIndex::<bool>::new(3);
AccountsIndex::<bool>::new(Some(3));
}
}

View File

@ -1190,7 +1190,7 @@ impl Bank {
accounts_db_caching_enabled,
shrink_ratio,
debug_do_not_add_builtins,
BINS_FOR_TESTING,
Some(BINS_FOR_TESTING),
)
}
@ -1215,7 +1215,7 @@ impl Bank {
accounts_db_caching_enabled,
shrink_ratio,
debug_do_not_add_builtins,
BINS_FOR_BENCHMARKS,
Some(BINS_FOR_BENCHMARKS),
)
}
@ -1230,7 +1230,7 @@ impl Bank {
accounts_db_caching_enabled: bool,
shrink_ratio: AccountShrinkThreshold,
debug_do_not_add_builtins: bool,
accounts_index_bins: usize,
accounts_index_bins: Option<usize>,
) -> Self {
let accounts = Accounts::new_with_config(
paths,

View File

@ -197,7 +197,7 @@ pub(crate) fn bank_from_streams<R>(
limit_load_slot_count_from_snapshot: Option<usize>,
shrink_ratio: AccountShrinkThreshold,
verify_index: bool,
accounts_index_bins: usize,
accounts_index_bins: Option<usize>,
) -> std::result::Result<Bank, Error>
where
R: Read,
@ -328,7 +328,7 @@ fn reconstruct_bank_from_fields<E>(
limit_load_slot_count_from_snapshot: Option<usize>,
shrink_ratio: AccountShrinkThreshold,
verify_index: bool,
accounts_index_bins: usize,
accounts_index_bins: Option<usize>,
) -> Result<Bank, Error>
where
E: SerializableStorage + std::marker::Sync,
@ -395,7 +395,7 @@ fn reconstruct_accountsdb_from_fields<E>(
limit_load_slot_count_from_snapshot: Option<usize>,
shrink_ratio: AccountShrinkThreshold,
verify_index: bool,
accounts_index_bins: usize,
accounts_index_bins: Option<usize>,
) -> Result<AccountsDb, Error>
where
E: SerializableStorage + std::marker::Sync,

View File

@ -81,7 +81,7 @@ where
None,
AccountShrinkThreshold::default(),
false,
crate::accounts_index::BINS_FOR_TESTING,
Some(crate::accounts_index::BINS_FOR_TESTING),
)
}
@ -243,7 +243,7 @@ fn test_bank_serialize_style(serde_style: SerdeStyle) {
None,
AccountShrinkThreshold::default(),
false,
crate::accounts_index::BINS_FOR_TESTING,
Some(crate::accounts_index::BINS_FOR_TESTING),
)
.unwrap();
dbank.src = ref_sc;

View File

@ -726,7 +726,7 @@ pub fn bank_from_snapshot_archives(
test_hash_calculation: bool,
accounts_db_skip_shrink: bool,
verify_index: bool,
accounts_index_bins: usize,
accounts_index_bins: Option<usize>,
) -> Result<(Bank, BankFromArchiveTimings)> {
check_are_snapshots_compatible(
full_snapshot_archive_info,
@ -833,7 +833,7 @@ pub fn bank_from_latest_snapshot_archives(
test_hash_calculation: bool,
accounts_db_skip_shrink: bool,
verify_index: bool,
accounts_index_bins: usize,
accounts_index_bins: Option<usize>,
) -> Result<(Bank, BankFromArchiveTimings)> {
let full_snapshot_archive_info = get_highest_full_snapshot_archive_info(&snapshot_archives_dir)
.ok_or(SnapshotError::NoSnapshotArchives)?;
@ -1371,7 +1371,7 @@ fn rebuild_bank_from_snapshots(
limit_load_slot_count_from_snapshot: Option<usize>,
shrink_ratio: AccountShrinkThreshold,
verify_index: bool,
accounts_index_bins: usize,
accounts_index_bins: Option<usize>,
) -> Result<Bank> {
let (full_snapshot_version, full_snapshot_root_paths) =
verify_unpacked_snapshots_dir_and_version(
@ -2490,7 +2490,7 @@ mod tests {
false,
false,
false,
crate::accounts_index::BINS_FOR_TESTING,
Some(crate::accounts_index::BINS_FOR_TESTING),
)
.unwrap();
@ -2581,7 +2581,7 @@ mod tests {
false,
false,
false,
crate::accounts_index::BINS_FOR_TESTING,
Some(crate::accounts_index::BINS_FOR_TESTING),
)
.unwrap();
@ -2691,7 +2691,7 @@ mod tests {
false,
false,
false,
crate::accounts_index::BINS_FOR_TESTING,
Some(crate::accounts_index::BINS_FOR_TESTING),
)
.unwrap();
@ -2790,7 +2790,7 @@ mod tests {
false,
false,
false,
crate::accounts_index::BINS_FOR_TESTING,
Some(crate::accounts_index::BINS_FOR_TESTING),
)
.unwrap();