Skip to content

Commit

Permalink
v1.18: Replaces DashMap with HashMap in secondary indexes (backport of
Browse files Browse the repository at this point in the history
…anza-xyz#1137) (anza-xyz#1155)

Replaces DashMap with HashMap in secondary indexes (anza-xyz#1137)

(cherry picked from commit 9606a13)

Co-authored-by: Brooks <brooks@anza.xyz>
  • Loading branch information
2 people authored and yihau committed May 14, 2024
1 parent 8635883 commit 10e5a10
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions accounts-db/src/accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ pub enum AccountsIndexScanResult {
pub struct AccountsIndex<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> {
pub account_maps: LockMapType<T, U>,
pub bin_calculator: PubkeyBinCalculator24,
program_id_index: SecondaryIndex<DashMapSecondaryIndexEntry>,
spl_token_mint_index: SecondaryIndex<DashMapSecondaryIndexEntry>,
program_id_index: SecondaryIndex<RwLockSecondaryIndexEntry>,
spl_token_mint_index: SecondaryIndex<RwLockSecondaryIndexEntry>,
spl_token_owner_index: SecondaryIndex<RwLockSecondaryIndexEntry>,
pub roots_tracker: RwLock<RootsTracker>,
ongoing_scan_roots: RwLock<BTreeMap<Slot, u64>>,
Expand Down Expand Up @@ -727,10 +727,10 @@ impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> AccountsIndex<T, U> {
Self {
account_maps,
bin_calculator,
program_id_index: SecondaryIndex::<DashMapSecondaryIndexEntry>::new(
program_id_index: SecondaryIndex::<RwLockSecondaryIndexEntry>::new(
"program_id_index_stats",
),
spl_token_mint_index: SecondaryIndex::<DashMapSecondaryIndexEntry>::new(
spl_token_mint_index: SecondaryIndex::<RwLockSecondaryIndexEntry>::new(
"spl_token_mint_index_stats",
),
spl_token_owner_index: SecondaryIndex::<RwLockSecondaryIndexEntry>::new(
Expand Down Expand Up @@ -2081,17 +2081,17 @@ pub mod tests {
}
}

fn create_dashmap_secondary_index_state() -> (usize, usize, AccountSecondaryIndexes) {
fn create_spl_token_mint_secondary_index_state() -> (usize, usize, AccountSecondaryIndexes) {
{
// Check that we're actually testing the correct variant
let index = AccountsIndex::<bool, bool>::default_for_tests();
let _type_check = SecondaryIndexTypes::DashMap(&index.spl_token_mint_index);
let _type_check = SecondaryIndexTypes::RwLock(&index.spl_token_mint_index);
}

(0, PUBKEY_BYTES, spl_token_mint_index_enabled())
}

fn create_rwlock_secondary_index_state() -> (usize, usize, AccountSecondaryIndexes) {
fn create_spl_token_owner_secondary_index_state() -> (usize, usize, AccountSecondaryIndexes) {
{
// Check that we're actually testing the correct variant
let index = AccountsIndex::<bool, bool>::default_for_tests();
Expand Down Expand Up @@ -3449,8 +3449,8 @@ pub mod tests {
}

#[test]
fn test_purge_exact_dashmap_secondary_index() {
let (key_start, key_end, secondary_indexes) = create_dashmap_secondary_index_state();
fn test_purge_exact_spl_token_mint_secondary_index() {
let (key_start, key_end, secondary_indexes) = create_spl_token_mint_secondary_index_state();
let index = AccountsIndex::<bool, bool>::default_for_tests();
run_test_purge_exact_secondary_index(
&index,
Expand All @@ -3462,8 +3462,9 @@ pub mod tests {
}

#[test]
fn test_purge_exact_rwlock_secondary_index() {
let (key_start, key_end, secondary_indexes) = create_rwlock_secondary_index_state();
fn test_purge_exact_spl_token_owner_secondary_index() {
let (key_start, key_end, secondary_indexes) =
create_spl_token_owner_secondary_index_state();
let index = AccountsIndex::<bool, bool>::default_for_tests();
run_test_purge_exact_secondary_index(
&index,
Expand Down Expand Up @@ -3667,8 +3668,8 @@ pub mod tests {
}

#[test]
fn test_dashmap_secondary_index() {
let (key_start, key_end, secondary_indexes) = create_dashmap_secondary_index_state();
fn test_spl_token_mint_secondary_index() {
let (key_start, key_end, secondary_indexes) = create_spl_token_mint_secondary_index_state();
let index = AccountsIndex::<bool, bool>::default_for_tests();
for token_id in [inline_spl_token::id(), inline_spl_token_2022::id()] {
run_test_spl_token_secondary_indexes(
Expand All @@ -3683,8 +3684,9 @@ pub mod tests {
}

#[test]
fn test_rwlock_secondary_index() {
let (key_start, key_end, secondary_indexes) = create_rwlock_secondary_index_state();
fn test_spl_token_owner_secondary_index() {
let (key_start, key_end, secondary_indexes) =
create_spl_token_owner_secondary_index_state();
let index = AccountsIndex::<bool, bool>::default_for_tests();
for token_id in [inline_spl_token::id(), inline_spl_token_2022::id()] {
run_test_spl_token_secondary_indexes(
Expand Down Expand Up @@ -3788,8 +3790,8 @@ pub mod tests {
}

#[test]
fn test_dashmap_secondary_index_same_slot_and_forks() {
let (key_start, key_end, account_index) = create_dashmap_secondary_index_state();
fn test_spl_token_mint_secondary_index_same_slot_and_forks() {
let (key_start, key_end, account_index) = create_spl_token_mint_secondary_index_state();
let index = AccountsIndex::<bool, bool>::default_for_tests();
for token_id in [inline_spl_token::id(), inline_spl_token_2022::id()] {
run_test_secondary_indexes_same_slot_and_forks(
Expand All @@ -3805,7 +3807,7 @@ pub mod tests {

#[test]
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_spl_token_owner_secondary_index_state();
let index = AccountsIndex::<bool, bool>::default_for_tests();
for token_id in [inline_spl_token::id(), inline_spl_token_2022::id()] {
run_test_secondary_indexes_same_slot_and_forks(
Expand Down

0 comments on commit 10e5a10

Please sign in to comment.