remove AccountsIndex::default (#19082)

* accounts_db calls AccountsDb::new(bins)

* remove AccountsIndex::default
This commit is contained in:
Jeff Washington (jwash) 2021-08-05 11:38:53 -05:00 committed by GitHub
parent 5cf28689e6
commit 24207a09ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 44 deletions

View File

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

View File

@ -9810,7 +9810,7 @@ pub mod tests {
#[test] #[test]
fn test_delete_dependencies() { fn test_delete_dependencies() {
solana_logger::setup(); solana_logger::setup();
let accounts_index = AccountsIndex::default(); let accounts_index = AccountsIndex::default_for_tests();
let key0 = Pubkey::new_from_array([0u8; 32]); let key0 = Pubkey::new_from_array([0u8; 32]);
let key1 = Pubkey::new_from_array([1u8; 32]); let key1 = Pubkey::new_from_array([1u8; 32]);
let key2 = Pubkey::new_from_array([2u8; 32]); let key2 = Pubkey::new_from_array([2u8; 32]);

View File

@ -741,16 +741,6 @@ pub struct AccountsIndex<T> {
pub removed_bank_ids: Mutex<HashSet<BankId>>, pub removed_bank_ids: Mutex<HashSet<BankId>>,
} }
impl<
T: 'static + Clone + IsCached + ZeroLamport + std::marker::Sync + std::marker::Send + Debug,
> Default for AccountsIndex<T>
{
fn default() -> Self {
// all test callers will move to default_for_tests
Self::new(BINS_DEFAULT)
}
}
impl< impl<
T: 'static + Clone + IsCached + ZeroLamport + std::marker::Sync + std::marker::Send + Debug, T: 'static + Clone + IsCached + ZeroLamport + std::marker::Sync + std::marker::Send + Debug,
> AccountsIndex<T> > AccountsIndex<T>
@ -1892,7 +1882,7 @@ pub mod tests {
fn create_dashmap_secondary_index_state() -> (usize, usize, AccountSecondaryIndexes) { fn create_dashmap_secondary_index_state() -> (usize, usize, AccountSecondaryIndexes) {
{ {
// Check that we're actually testing the correct variant // Check that we're actually testing the correct variant
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
let _type_check = SecondaryIndexTypes::DashMap(&index.spl_token_mint_index); let _type_check = SecondaryIndexTypes::DashMap(&index.spl_token_mint_index);
} }
@ -1902,7 +1892,7 @@ pub mod tests {
fn create_rwlock_secondary_index_state() -> (usize, usize, AccountSecondaryIndexes) { fn create_rwlock_secondary_index_state() -> (usize, usize, AccountSecondaryIndexes) {
{ {
// Check that we're actually testing the correct variant // Check that we're actually testing the correct variant
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
let _type_check = SecondaryIndexTypes::RwLock(&index.spl_token_owner_index); let _type_check = SecondaryIndexTypes::RwLock(&index.spl_token_owner_index);
} }
@ -2556,7 +2546,7 @@ pub mod tests {
#[test] #[test]
fn test_get_empty() { fn test_get_empty() {
let key = Keypair::new(); let key = Keypair::new();
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
let ancestors = Ancestors::default(); let ancestors = Ancestors::default();
assert!(index.get(&key.pubkey(), Some(&ancestors), None).is_none()); assert!(index.get(&key.pubkey(), Some(&ancestors), None).is_none());
assert!(index.get(&key.pubkey(), None, None).is_none()); assert!(index.get(&key.pubkey(), None, None).is_none());
@ -2614,7 +2604,7 @@ pub mod tests {
#[test] #[test]
fn test_insert_no_ancestors() { fn test_insert_no_ancestors() {
let key = Keypair::new(); let key = Keypair::new();
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
let mut gc = Vec::new(); let mut gc = Vec::new();
index.upsert( index.upsert(
0, 0,
@ -2655,7 +2645,7 @@ pub mod tests {
let pubkey = &key.pubkey(); let pubkey = &key.pubkey();
let slot = 0; let slot = 0;
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
let account_info = true; let account_info = true;
let items = vec![(*pubkey, account_info)]; let items = vec![(*pubkey, account_info)];
index.insert_new_if_missing_into_primary_index(slot, items.len(), items.into_iter()); index.insert_new_if_missing_into_primary_index(slot, items.len(), items.into_iter());
@ -2674,7 +2664,7 @@ pub mod tests {
assert_eq!(num, 1); assert_eq!(num, 1);
// not zero lamports // not zero lamports
let index = AccountsIndex::<AccountInfoTest>::default(); let index = AccountsIndex::<AccountInfoTest>::default_for_tests();
let account_info: AccountInfoTest = 0 as AccountInfoTest; let account_info: AccountInfoTest = 0 as AccountInfoTest;
let items = vec![(*pubkey, account_info)]; let items = vec![(*pubkey, account_info)];
index.insert_new_if_missing_into_primary_index(slot, items.len(), items.into_iter()); index.insert_new_if_missing_into_primary_index(slot, items.len(), items.into_iter());
@ -2725,7 +2715,7 @@ pub mod tests {
let key0 = Keypair::new().pubkey(); let key0 = Keypair::new().pubkey();
let key1 = Keypair::new().pubkey(); let key1 = Keypair::new().pubkey();
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
let account_infos = [true, false]; let account_infos = [true, false];
let items = vec![(key0, account_infos[0]), (key1, account_infos[1])]; let items = vec![(key0, account_infos[0]), (key1, account_infos[1])];
@ -2756,7 +2746,7 @@ pub mod tests {
let slot1 = 1; let slot1 = 1;
let key = Keypair::new().pubkey(); let key = Keypair::new().pubkey();
let index = AccountsIndex::<T>::default(); let index = AccountsIndex::<T>::default_for_tests();
let mut gc = Vec::new(); let mut gc = Vec::new();
if upsert { if upsert {
@ -2857,7 +2847,7 @@ pub mod tests {
#[test] #[test]
fn test_insert_with_lock_no_ancestors() { fn test_insert_with_lock_no_ancestors() {
let key = Keypair::new(); let key = Keypair::new();
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
let slot = 0; let slot = 0;
let account_info = true; let account_info = true;
@ -2903,7 +2893,7 @@ pub mod tests {
#[test] #[test]
fn test_insert_wrong_ancestors() { fn test_insert_wrong_ancestors() {
let key = Keypair::new(); let key = Keypair::new();
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
let mut gc = Vec::new(); let mut gc = Vec::new();
index.upsert( index.upsert(
0, 0,
@ -2927,7 +2917,7 @@ pub mod tests {
#[test] #[test]
fn test_insert_with_ancestors() { fn test_insert_with_ancestors() {
let key = Keypair::new(); let key = Keypair::new();
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
let mut gc = Vec::new(); let mut gc = Vec::new();
index.upsert( index.upsert(
0, 0,
@ -2957,7 +2947,7 @@ pub mod tests {
} }
fn setup_accounts_index_keys(num_pubkeys: usize) -> (AccountsIndex<bool>, Vec<Pubkey>) { fn setup_accounts_index_keys(num_pubkeys: usize) -> (AccountsIndex<bool>, Vec<Pubkey>) {
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
let root_slot = 0; let root_slot = 0;
let mut pubkeys: Vec<Pubkey> = std::iter::repeat_with(|| { let mut pubkeys: Vec<Pubkey> = std::iter::repeat_with(|| {
@ -3123,7 +3113,7 @@ pub mod tests {
#[test] #[test]
fn test_is_root() { fn test_is_root() {
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
assert!(!index.is_root(0)); assert!(!index.is_root(0));
index.add_root(0, false); index.add_root(0, false);
assert!(index.is_root(0)); assert!(index.is_root(0));
@ -3132,7 +3122,7 @@ pub mod tests {
#[test] #[test]
fn test_insert_with_root() { fn test_insert_with_root() {
let key = Keypair::new(); let key = Keypair::new();
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
let mut gc = Vec::new(); let mut gc = Vec::new();
index.upsert( index.upsert(
0, 0,
@ -3152,7 +3142,7 @@ pub mod tests {
#[test] #[test]
fn test_clean_first() { fn test_clean_first() {
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
index.add_root(0, false); index.add_root(0, false);
index.add_root(1, false); index.add_root(1, false);
index.clean_dead_slot(0); index.clean_dead_slot(0);
@ -3163,7 +3153,7 @@ pub mod tests {
#[test] #[test]
fn test_clean_last() { fn test_clean_last() {
//this behavior might be undefined, clean up should only occur on older slots //this behavior might be undefined, clean up should only occur on older slots
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
index.add_root(0, false); index.add_root(0, false);
index.add_root(1, false); index.add_root(1, false);
index.clean_dead_slot(1); index.clean_dead_slot(1);
@ -3173,7 +3163,7 @@ pub mod tests {
#[test] #[test]
fn test_clean_and_unclean_slot() { fn test_clean_and_unclean_slot() {
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
assert_eq!(0, index.roots_tracker.read().unwrap().uncleaned_roots.len()); assert_eq!(0, index.roots_tracker.read().unwrap().uncleaned_roots.len());
index.add_root(0, false); index.add_root(0, false);
index.add_root(1, false); index.add_root(1, false);
@ -3245,7 +3235,7 @@ pub mod tests {
#[test] #[test]
fn test_update_last_wins() { fn test_update_last_wins() {
let key = Keypair::new(); let key = Keypair::new();
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
let ancestors = vec![(0, 0)].into_iter().collect(); let ancestors = vec![(0, 0)].into_iter().collect();
let mut gc = Vec::new(); let mut gc = Vec::new();
index.upsert( index.upsert(
@ -3281,7 +3271,7 @@ pub mod tests {
fn test_update_new_slot() { fn test_update_new_slot() {
solana_logger::setup(); solana_logger::setup();
let key = Keypair::new(); let key = Keypair::new();
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
let ancestors = vec![(0, 0)].into_iter().collect(); let ancestors = vec![(0, 0)].into_iter().collect();
let mut gc = Vec::new(); let mut gc = Vec::new();
index.upsert( index.upsert(
@ -3314,7 +3304,7 @@ pub mod tests {
#[test] #[test]
fn test_update_gc_purged_slot() { fn test_update_gc_purged_slot() {
let key = Keypair::new(); let key = Keypair::new();
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
let mut gc = Vec::new(); let mut gc = Vec::new();
index.upsert( index.upsert(
0, 0,
@ -3407,7 +3397,7 @@ pub mod tests {
#[test] #[test]
fn test_purge() { fn test_purge() {
let key = Keypair::new(); let key = Keypair::new();
let index = AccountsIndex::<u64>::default(); let index = AccountsIndex::<u64>::default_for_tests();
let mut gc = Vec::new(); let mut gc = Vec::new();
assert_eq!(0, account_maps_len_expensive(&index)); assert_eq!(0, account_maps_len_expensive(&index));
index.upsert( index.upsert(
@ -3455,7 +3445,7 @@ pub mod tests {
#[test] #[test]
fn test_latest_slot() { fn test_latest_slot() {
let slot_slice = vec![(0, true), (5, true), (3, true), (7, true)]; let slot_slice = vec![(0, true), (5, true), (3, true), (7, true)];
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
// No ancestors, no root, should return None // No ancestors, no root, should return None
assert!(index.latest_slot(None, &slot_slice, None).is_none()); assert!(index.latest_slot(None, &slot_slice, None).is_none());
@ -3557,7 +3547,7 @@ pub mod tests {
#[test] #[test]
fn test_purge_exact_dashmap_secondary_index() { fn test_purge_exact_dashmap_secondary_index() {
let (key_start, key_end, secondary_indexes) = create_dashmap_secondary_index_state(); let (key_start, key_end, secondary_indexes) = create_dashmap_secondary_index_state();
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
run_test_purge_exact_secondary_index( run_test_purge_exact_secondary_index(
&index, &index,
&index.spl_token_mint_index, &index.spl_token_mint_index,
@ -3570,7 +3560,7 @@ pub mod tests {
#[test] #[test]
fn test_purge_exact_rwlock_secondary_index() { fn test_purge_exact_rwlock_secondary_index() {
let (key_start, key_end, secondary_indexes) = create_rwlock_secondary_index_state(); let (key_start, key_end, secondary_indexes) = create_rwlock_secondary_index_state();
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
run_test_purge_exact_secondary_index( run_test_purge_exact_secondary_index(
&index, &index,
&index.spl_token_owner_index, &index.spl_token_owner_index,
@ -3583,7 +3573,7 @@ pub mod tests {
#[test] #[test]
fn test_purge_older_root_entries() { fn test_purge_older_root_entries() {
// No roots, should be no reclaims // No roots, should be no reclaims
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
let mut slot_list = vec![(1, true), (2, true), (5, true), (9, true)]; let mut slot_list = vec![(1, true), (2, true), (5, true), (9, true)];
let mut reclaims = vec![]; let mut reclaims = vec![];
index.purge_older_root_entries(&mut slot_list, &mut reclaims, None); index.purge_older_root_entries(&mut slot_list, &mut reclaims, None);
@ -3778,7 +3768,7 @@ pub mod tests {
#[test] #[test]
fn test_dashmap_secondary_index() { fn test_dashmap_secondary_index() {
let (key_start, key_end, secondary_indexes) = create_dashmap_secondary_index_state(); let (key_start, key_end, secondary_indexes) = create_dashmap_secondary_index_state();
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
run_test_secondary_indexes( run_test_secondary_indexes(
&index, &index,
&index.spl_token_mint_index, &index.spl_token_mint_index,
@ -3791,7 +3781,7 @@ pub mod tests {
#[test] #[test]
fn test_rwlock_secondary_index() { fn test_rwlock_secondary_index() {
let (key_start, key_end, secondary_indexes) = create_rwlock_secondary_index_state(); let (key_start, key_end, secondary_indexes) = create_rwlock_secondary_index_state();
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
run_test_secondary_indexes( run_test_secondary_indexes(
&index, &index,
&index.spl_token_owner_index, &index.spl_token_owner_index,
@ -3892,7 +3882,7 @@ pub mod tests {
#[test] #[test]
fn test_dashmap_secondary_index_same_slot_and_forks() { fn test_dashmap_secondary_index_same_slot_and_forks() {
let (key_start, key_end, account_index) = create_dashmap_secondary_index_state(); let (key_start, key_end, account_index) = create_dashmap_secondary_index_state();
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
run_test_secondary_indexes_same_slot_and_forks( run_test_secondary_indexes_same_slot_and_forks(
&index, &index,
&index.spl_token_mint_index, &index.spl_token_mint_index,
@ -3905,7 +3895,7 @@ pub mod tests {
#[test] #[test]
fn test_rwlock_secondary_index_same_slot_and_forks() { fn test_rwlock_secondary_index_same_slot_and_forks() {
let (key_start, key_end, account_index) = create_rwlock_secondary_index_state(); let (key_start, key_end, account_index) = create_rwlock_secondary_index_state();
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
run_test_secondary_indexes_same_slot_and_forks( run_test_secondary_indexes_same_slot_and_forks(
&index, &index,
&index.spl_token_owner_index, &index.spl_token_owner_index,
@ -3929,7 +3919,7 @@ pub mod tests {
#[test] #[test]
fn test_bin_start_and_range() { fn test_bin_start_and_range() {
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
let iter = AccountsIndexIterator::new(&index, None::<RangeInclusive<Pubkey>>); let iter = AccountsIndexIterator::new(&index, None::<RangeInclusive<Pubkey>>);
assert_eq!((0, usize::MAX), iter.bin_start_and_range()); assert_eq!((0, usize::MAX), iter.bin_start_and_range());
@ -3958,7 +3948,7 @@ pub mod tests {
#[test] #[test]
fn test_start_end_bin() { fn test_start_end_bin() {
let index = AccountsIndex::<bool>::default(); let index = AccountsIndex::<bool>::default_for_tests();
assert_eq!(index.bins(), BINS_DEFAULT); assert_eq!(index.bins(), BINS_DEFAULT);
let iter = AccountsIndexIterator::new(&index, None::<RangeInclusive<Pubkey>>); let iter = AccountsIndexIterator::new(&index, None::<RangeInclusive<Pubkey>>);
assert_eq!(iter.start_bin(), 0); // no range, so 0 assert_eq!(iter.start_bin(), 0); // no range, so 0