type AccountSecondaryIndexes = HashSet (#17108)

This commit is contained in:
Jeff Washington (jwash)
2021-05-10 09:22:48 -05:00
committed by GitHub
parent a6a1355b80
commit f39dda00e0
13 changed files with 224 additions and 139 deletions

View File

@@ -74,6 +74,8 @@ pub enum AccountIndex {
SplTokenOwner,
}
pub type AccountSecondaryIndexes = HashSet<AccountIndex>;
#[derive(Debug)]
pub struct AccountMapEntryInner<T> {
ref_count: AtomicU64,
@@ -819,7 +821,11 @@ impl<T: 'static + Clone + IsCached + ZeroLamport> AccountsIndex<T> {
(w_account_entry.unwrap(), is_newly_inserted)
}
pub fn handle_dead_keys(&self, dead_keys: &[&Pubkey], account_indexes: &HashSet<AccountIndex>) {
pub fn handle_dead_keys(
&self,
dead_keys: &[&Pubkey],
account_indexes: &AccountSecondaryIndexes,
) {
if !dead_keys.is_empty() {
for key in dead_keys.iter() {
let mut w_index = self.account_maps.write().unwrap();
@@ -923,7 +929,7 @@ impl<T: 'static + Clone + IsCached + ZeroLamport> AccountsIndex<T> {
pubkey: &Pubkey,
slots_to_purge: &'a C,
reclaims: &mut SlotList<T>,
account_indexes: &HashSet<AccountIndex>,
account_indexes: &AccountSecondaryIndexes,
) -> bool
where
C: Contains<'a, Slot>,
@@ -1051,7 +1057,7 @@ impl<T: 'static + Clone + IsCached + ZeroLamport> AccountsIndex<T> {
slot: Slot,
account_owner: &Pubkey,
account_data: &[u8],
account_indexes: &HashSet<AccountIndex>,
account_indexes: &AccountSecondaryIndexes,
) {
if account_indexes.is_empty() {
return;
@@ -1103,7 +1109,7 @@ impl<T: 'static + Clone + IsCached + ZeroLamport> AccountsIndex<T> {
pubkey: &Pubkey,
account_owner: &Pubkey,
account_data: &[u8],
account_indexes: &HashSet<AccountIndex>,
account_indexes: &AccountSecondaryIndexes,
account_info: T,
reclaims: &mut SlotList<T>,
) {
@@ -1126,7 +1132,7 @@ impl<T: 'static + Clone + IsCached + ZeroLamport> AccountsIndex<T> {
pubkey: &Pubkey,
account_owner: &Pubkey,
account_data: &[u8],
account_indexes: &HashSet<AccountIndex>,
account_indexes: &AccountSecondaryIndexes,
account_info: T,
reclaims: &mut SlotList<T>,
) -> bool {
@@ -1180,7 +1186,7 @@ impl<T: 'static + Clone + IsCached + ZeroLamport> AccountsIndex<T> {
&'a self,
inner_key: &Pubkey,
slots_to_remove: Option<&'a C>,
account_indexes: &HashSet<AccountIndex>,
account_indexes: &AccountSecondaryIndexes,
) where
C: Contains<'a, Slot>,
{
@@ -1206,7 +1212,7 @@ impl<T: 'static + Clone + IsCached + ZeroLamport> AccountsIndex<T> {
slot_list: &mut SlotList<T>,
reclaims: &mut SlotList<T>,
max_clean_root: Option<Slot>,
account_indexes: &HashSet<AccountIndex>,
account_indexes: &AccountSecondaryIndexes,
) {
let roots_tracker = &self.roots_tracker.read().unwrap();
let newest_root_in_slot_list =
@@ -1233,7 +1239,7 @@ impl<T: 'static + Clone + IsCached + ZeroLamport> AccountsIndex<T> {
pubkey: &Pubkey,
reclaims: &mut SlotList<T>,
max_clean_root: Option<Slot>,
account_indexes: &HashSet<AccountIndex>,
account_indexes: &AccountSecondaryIndexes,
) {
let mut is_slot_list_empty = false;
if let Some(mut locked_entry) = self.get_account_write_entry(pubkey) {
@@ -1438,13 +1444,13 @@ pub mod tests {
DashMap(&'a SecondaryIndex<DashMapSecondaryIndexEntry>),
}
pub fn spl_token_mint_index_enabled() -> HashSet<AccountIndex> {
pub fn spl_token_mint_index_enabled() -> AccountSecondaryIndexes {
let mut account_indexes = HashSet::new();
account_indexes.insert(AccountIndex::SplTokenMint);
account_indexes
}
pub fn spl_token_owner_index_enabled() -> HashSet<AccountIndex> {
pub fn spl_token_owner_index_enabled() -> AccountSecondaryIndexes {
let mut account_indexes = HashSet::new();
account_indexes.insert(AccountIndex::SplTokenOwner);
account_indexes
@@ -1476,7 +1482,7 @@ pub mod tests {
}
}
fn create_dashmap_secondary_index_state() -> (usize, usize, HashSet<AccountIndex>) {
fn create_dashmap_secondary_index_state() -> (usize, usize, AccountSecondaryIndexes) {
{
// Check that we're actually testing the correct variant
let index = AccountsIndex::<bool>::default();
@@ -1486,7 +1492,7 @@ pub mod tests {
(0, PUBKEY_BYTES, spl_token_mint_index_enabled())
}
fn create_rwlock_secondary_index_state() -> (usize, usize, HashSet<AccountIndex>) {
fn create_rwlock_secondary_index_state() -> (usize, usize, AccountSecondaryIndexes) {
{
// Check that we're actually testing the correct variant
let index = AccountsIndex::<bool>::default();
@@ -2074,7 +2080,7 @@ pub mod tests {
&key.pubkey(),
&Pubkey::default(),
&[],
&HashSet::new(),
&AccountSecondaryIndexes::default(),
true,
&mut gc,
);
@@ -2099,7 +2105,7 @@ pub mod tests {
&key.pubkey(),
&Pubkey::default(),
&[],
&HashSet::new(),
&AccountSecondaryIndexes::default(),
true,
&mut gc,
);
@@ -2123,7 +2129,7 @@ pub mod tests {
&key.pubkey(),
&Pubkey::default(),
&[],
&HashSet::new(),
&AccountSecondaryIndexes::default(),
true,
&mut gc,
);
@@ -2156,7 +2162,7 @@ pub mod tests {
&new_pubkey,
&Pubkey::default(),
&[],
&HashSet::new(),
&AccountSecondaryIndexes::default(),
true,
&mut vec![],
);
@@ -2172,7 +2178,7 @@ pub mod tests {
&Pubkey::default(),
&Pubkey::default(),
&[],
&HashSet::new(),
&AccountSecondaryIndexes::default(),
true,
&mut vec![],
);
@@ -2303,7 +2309,7 @@ pub mod tests {
&solana_sdk::pubkey::new_rand(),
&Pubkey::default(),
&[],
&HashSet::new(),
&AccountSecondaryIndexes::default(),
true,
&mut gc,
);
@@ -2328,7 +2334,7 @@ pub mod tests {
&key.pubkey(),
&Pubkey::default(),
&[],
&HashSet::new(),
&AccountSecondaryIndexes::default(),
true,
&mut gc,
);
@@ -2442,7 +2448,7 @@ pub mod tests {
&key.pubkey(),
&Pubkey::default(),
&[],
&HashSet::new(),
&AccountSecondaryIndexes::default(),
true,
&mut gc,
);
@@ -2457,7 +2463,7 @@ pub mod tests {
&key.pubkey(),
&Pubkey::default(),
&[],
&HashSet::new(),
&AccountSecondaryIndexes::default(),
false,
&mut gc,
);
@@ -2478,7 +2484,7 @@ pub mod tests {
&key.pubkey(),
&Pubkey::default(),
&[],
&HashSet::new(),
&AccountSecondaryIndexes::default(),
true,
&mut gc,
);
@@ -2488,7 +2494,7 @@ pub mod tests {
&key.pubkey(),
&Pubkey::default(),
&[],
&HashSet::new(),
&AccountSecondaryIndexes::default(),
false,
&mut gc,
);
@@ -2510,7 +2516,7 @@ pub mod tests {
&key.pubkey(),
&Pubkey::default(),
&[],
&HashSet::new(),
&AccountSecondaryIndexes::default(),
true,
&mut gc,
);
@@ -2520,7 +2526,7 @@ pub mod tests {
&key.pubkey(),
&Pubkey::default(),
&[],
&HashSet::new(),
&AccountSecondaryIndexes::default(),
false,
&mut gc,
);
@@ -2529,7 +2535,7 @@ pub mod tests {
&key.pubkey(),
&Pubkey::default(),
&[],
&HashSet::new(),
&AccountSecondaryIndexes::default(),
true,
&mut gc,
);
@@ -2538,7 +2544,7 @@ pub mod tests {
&key.pubkey(),
&Pubkey::default(),
&[],
&HashSet::new(),
&AccountSecondaryIndexes::default(),
true,
&mut gc,
);
@@ -2550,7 +2556,7 @@ pub mod tests {
&key.pubkey(),
&Pubkey::default(),
&[],
&HashSet::new(),
&AccountSecondaryIndexes::default(),
true,
&mut gc,
);
@@ -2584,7 +2590,7 @@ pub mod tests {
&key.pubkey(),
&Pubkey::default(),
&[],
&HashSet::new(),
&AccountSecondaryIndexes::default(),
12,
&mut gc
));
@@ -2594,7 +2600,7 @@ pub mod tests {
&key.pubkey(),
&Pubkey::default(),
&[],
&HashSet::new(),
&AccountSecondaryIndexes::default(),
10,
&mut gc
));
@@ -2611,7 +2617,7 @@ pub mod tests {
&key.pubkey(),
&Pubkey::default(),
&[],
&HashSet::new(),
&AccountSecondaryIndexes::default(),
9,
&mut gc
));
@@ -2667,7 +2673,7 @@ pub mod tests {
secondary_index: &SecondaryIndex<SecondaryIndexEntryType>,
key_start: usize,
key_end: usize,
account_index: &HashSet<AccountIndex>,
account_index: &AccountSecondaryIndexes,
) {
// No roots, should be no reclaims
let slots = vec![1, 2, 5, 9];
@@ -2756,7 +2762,7 @@ pub mod tests {
&mut slot_list,
&mut reclaims,
None,
&HashSet::new(),
&AccountSecondaryIndexes::default(),
);
assert!(reclaims.is_empty());
assert_eq!(slot_list, vec![(1, true), (2, true), (5, true), (9, true)]);
@@ -2772,7 +2778,7 @@ pub mod tests {
&mut slot_list,
&mut reclaims,
None,
&HashSet::new(),
&AccountSecondaryIndexes::default(),
);
assert_eq!(reclaims, vec![(1, true), (2, true)]);
assert_eq!(slot_list, vec![(5, true), (9, true)]);
@@ -2786,7 +2792,7 @@ pub mod tests {
&mut slot_list,
&mut reclaims,
None,
&HashSet::new(),
&AccountSecondaryIndexes::default(),
);
assert_eq!(reclaims, vec![(1, true), (2, true)]);
assert_eq!(slot_list, vec![(5, true), (9, true)]);
@@ -2800,7 +2806,7 @@ pub mod tests {
&mut slot_list,
&mut reclaims,
Some(6),
&HashSet::new(),
&AccountSecondaryIndexes::default(),
);
assert_eq!(reclaims, vec![(1, true), (2, true)]);
assert_eq!(slot_list, vec![(5, true), (9, true)]);
@@ -2813,7 +2819,7 @@ pub mod tests {
&mut slot_list,
&mut reclaims,
Some(5),
&HashSet::new(),
&AccountSecondaryIndexes::default(),
);
assert_eq!(reclaims, vec![(1, true), (2, true)]);
assert_eq!(slot_list, vec![(5, true), (9, true)]);
@@ -2827,7 +2833,7 @@ pub mod tests {
&mut slot_list,
&mut reclaims,
Some(2),
&HashSet::new(),
&AccountSecondaryIndexes::default(),
);
assert!(reclaims.is_empty());
assert_eq!(slot_list, vec![(1, true), (2, true), (5, true), (9, true)]);
@@ -2841,7 +2847,7 @@ pub mod tests {
&mut slot_list,
&mut reclaims,
Some(1),
&HashSet::new(),
&AccountSecondaryIndexes::default(),
);
assert!(reclaims.is_empty());
assert_eq!(slot_list, vec![(1, true), (2, true), (5, true), (9, true)]);
@@ -2855,7 +2861,7 @@ pub mod tests {
&mut slot_list,
&mut reclaims,
Some(7),
&HashSet::new(),
&AccountSecondaryIndexes::default(),
);
assert_eq!(reclaims, vec![(1, true), (2, true)]);
assert_eq!(slot_list, vec![(5, true), (9, true)]);
@@ -2894,7 +2900,7 @@ pub mod tests {
secondary_index: &SecondaryIndex<SecondaryIndexEntryType>,
key_start: usize,
key_end: usize,
account_index: &HashSet<AccountIndex>,
account_index: &AccountSecondaryIndexes,
) {
let account_key = Pubkey::new_unique();
let index_key = Pubkey::new_unique();
@@ -2988,7 +2994,7 @@ pub mod tests {
secondary_index: &SecondaryIndex<SecondaryIndexEntryType>,
index_key_start: usize,
index_key_end: usize,
account_index: &HashSet<AccountIndex>,
account_index: &AccountSecondaryIndexes,
) {
let account_key = Pubkey::new_unique();
let secondary_key1 = Pubkey::new_unique();