introduce LockMapType for accounts_index (#18021) (#18051)

(cherry picked from commit 0a81c37fce)

Co-authored-by: Jeff Washington (jwash) <75863576+jeffwashington@users.noreply.github.com>
This commit is contained in:
mergify[bot]
2021-06-18 01:39:27 +00:00
committed by GitHub
parent d159ae9342
commit c65c580b20

View File

@ -513,7 +513,7 @@ pub struct AccountsIndexRootsStats {
} }
pub struct AccountsIndexIterator<'a, T> { pub struct AccountsIndexIterator<'a, T> {
account_maps: &'a RwLock<AccountMap<Pubkey, AccountMapEntry<T>>>, account_maps: &'a LockMapType<T>,
start_bound: Bound<Pubkey>, start_bound: Bound<Pubkey>,
end_bound: Bound<Pubkey>, end_bound: Bound<Pubkey>,
is_finished: bool, is_finished: bool,
@ -528,10 +528,7 @@ impl<'a, T> AccountsIndexIterator<'a, T> {
} }
} }
pub fn new<R>( pub fn new<R>(account_maps: &'a LockMapType<T>, range: Option<R>) -> Self
account_maps: &'a RwLock<AccountMap<Pubkey, AccountMapEntry<T>>>,
range: Option<R>,
) -> Self
where where
R: RangeBounds<Pubkey>, R: RangeBounds<Pubkey>,
{ {
@ -581,12 +578,13 @@ pub trait ZeroLamport {
} }
type MapType<T> = AccountMap<Pubkey, AccountMapEntry<T>>; type MapType<T> = AccountMap<Pubkey, AccountMapEntry<T>>;
type AccountMapsWriteLock<'a, T> = RwLockWriteGuard<'a, AccountMap<Pubkey, AccountMapEntry<T>>>; type LockMapType<T> = RwLock<MapType<T>>;
type AccountMapsReadLock<'a, T> = RwLockReadGuard<'a, AccountMap<Pubkey, AccountMapEntry<T>>>; type AccountMapsWriteLock<'a, T> = RwLockWriteGuard<'a, MapType<T>>;
type AccountMapsReadLock<'a, T> = RwLockReadGuard<'a, MapType<T>>;
#[derive(Debug)] #[derive(Debug)]
pub struct AccountsIndex<T> { pub struct AccountsIndex<T> {
pub account_maps: RwLock<MapType<T>>, pub account_maps: LockMapType<T>,
program_id_index: SecondaryIndex<DashMapSecondaryIndexEntry>, program_id_index: SecondaryIndex<DashMapSecondaryIndexEntry>,
spl_token_mint_index: SecondaryIndex<DashMapSecondaryIndexEntry>, spl_token_mint_index: SecondaryIndex<DashMapSecondaryIndexEntry>,
spl_token_owner_index: SecondaryIndex<RwLockSecondaryIndexEntry>, spl_token_owner_index: SecondaryIndex<RwLockSecondaryIndexEntry>,
@ -598,7 +596,7 @@ pub struct AccountsIndex<T> {
impl<T> Default for AccountsIndex<T> { impl<T> Default for AccountsIndex<T> {
fn default() -> Self { fn default() -> Self {
Self { Self {
account_maps: RwLock::<AccountMap<Pubkey, AccountMapEntry<T>>>::default(), account_maps: LockMapType::<T>::default(),
program_id_index: SecondaryIndex::<DashMapSecondaryIndexEntry>::new( program_id_index: SecondaryIndex::<DashMapSecondaryIndexEntry>::new(
"program_id_index_stats", "program_id_index_stats",
), ),