some basic accounts index refactoring (#19510)

This commit is contained in:
Jeff Washington (jwash) 2021-08-30 18:40:10 -05:00 committed by GitHub
parent 6cfd44b811
commit a655b01700
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,17 +30,19 @@ use thiserror::Error;
pub const ITER_BATCH_SIZE: usize = 1000;
pub const BINS_DEFAULT: usize = 8192;
pub const BINS_FOR_TESTING: usize = BINS_DEFAULT;
pub const BINS_FOR_BENCHMARKS: usize = BINS_DEFAULT;
pub const ACCOUNTS_INDEX_CONFIG_FOR_TESTING: AccountsIndexConfig = AccountsIndexConfig {
bins: Some(BINS_DEFAULT),
bins: Some(BINS_FOR_TESTING),
};
pub const ACCOUNTS_INDEX_CONFIG_FOR_BENCHMARKS: AccountsIndexConfig = AccountsIndexConfig {
bins: Some(BINS_DEFAULT),
bins: Some(BINS_FOR_BENCHMARKS),
};
pub type ScanResult<T> = Result<T, ScanError>;
pub type SlotList<T> = Vec<(Slot, T)>;
pub type SlotSlice<'s, T> = &'s [(Slot, T)];
pub type RefCount = u64;
pub type AccountMap<K, V> = HashMap<K, V>;
pub type AccountMap<V> = HashMap<Pubkey, V>;
type AccountMapEntry<T> = Arc<AccountMapEntryInner<T>>;
@ -117,21 +119,21 @@ impl<T> AccountMapEntryInner<T> {
}
}
pub enum AccountIndexGetResult<'a, T: 'static> {
pub enum AccountIndexGetResult<'a, T: IsCached> {
Found(ReadAccountMapEntry<T>, usize),
NotFoundOnFork,
Missing(AccountMapsReadLock<'a, T>),
}
#[self_referencing]
pub struct ReadAccountMapEntry<T: 'static> {
pub struct ReadAccountMapEntry<T: IsCached> {
owned_entry: AccountMapEntry<T>,
#[borrows(owned_entry)]
#[covariant]
slot_list_guard: RwLockReadGuard<'this, SlotList<T>>,
}
impl<T: Clone> ReadAccountMapEntry<T> {
impl<T: IsCached> ReadAccountMapEntry<T> {
pub fn from_account_map_entry(account_map_entry: AccountMapEntry<T>) -> Self {
ReadAccountMapEntryBuilder {
owned_entry: account_map_entry,
@ -162,7 +164,7 @@ impl<T: Clone> ReadAccountMapEntry<T> {
}
#[self_referencing]
pub struct WriteAccountMapEntry<T: 'static> {
pub struct WriteAccountMapEntry<T: IsCached> {
owned_entry: AccountMapEntry<T>,
#[borrows(owned_entry)]
#[covariant]
@ -709,7 +711,7 @@ impl<'a, T> AccountsIndexIterator<'a, T> {
}
}
impl<'a, T: 'static + Clone> Iterator for AccountsIndexIterator<'a, T> {
impl<'a, T: IsCached> Iterator for AccountsIndexIterator<'a, T> {
type Item = Vec<(Pubkey, AccountMapEntry<T>)>;
fn next(&mut self) -> Option<Self::Item> {
if self.is_finished {
@ -747,7 +749,7 @@ pub trait ZeroLamport {
fn is_zero_lamport(&self) -> bool;
}
type MapType<T> = AccountMap<Pubkey, AccountMapEntry<T>>;
type MapType<T> = AccountMap<AccountMapEntry<T>>;
type LockMapType<T> = Vec<RwLock<MapType<T>>>;
type LockMapTypeSlice<T> = [RwLock<MapType<T>>];
type AccountMapsWriteLock<'a, T> = RwLockWriteGuard<'a, MapType<T>>;
@ -1953,7 +1955,7 @@ pub mod tests {
}
}
impl<'a, T: 'static> AccountIndexGetResult<'a, T> {
impl<'a, T: IsCached> AccountIndexGetResult<'a, T> {
pub fn unwrap(self) -> (ReadAccountMapEntry<T>, usize) {
match self {
AccountIndexGetResult::Found(lock, size) => (lock, size),