Struct solana_runtime::accounts_index::AccountsIndex
source · pub struct AccountsIndex<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> {Show 15 fields
pub account_maps: Vec<AccountMap<T, U>>,
pub bin_calculator: PubkeyBinCalculator24,
program_id_index: SecondaryIndex<DashMapSecondaryIndexEntry>,
spl_token_mint_index: SecondaryIndex<DashMapSecondaryIndexEntry>,
spl_token_owner_index: SecondaryIndex<RwLockSecondaryIndexEntry>,
pub(crate) roots_tracker: RwLock<RootsTracker>,
ongoing_scan_roots: RwLock<BTreeMap<Slot, u64>>,
pub removed_bank_ids: Mutex<HashSet<BankId>>,
storage: AccountsIndexStorage<T, U>,
pub scan_results_limit_bytes: Option<usize>,
pub roots_added: AtomicUsize,
pub roots_removed: AtomicUsize,
pub active_scans: AtomicUsize,
pub max_distance_to_min_scan_slot: AtomicU64,
pub rent_paying_accounts_by_partition: OnceCell<RentPayingAccountsByPartition>,
}
Expand description
T: account info type to interact in in-memory items U: account info type to be persisted to disk
Fields§
§account_maps: Vec<AccountMap<T, U>>
§bin_calculator: PubkeyBinCalculator24
§program_id_index: SecondaryIndex<DashMapSecondaryIndexEntry>
§spl_token_mint_index: SecondaryIndex<DashMapSecondaryIndexEntry>
§spl_token_owner_index: SecondaryIndex<RwLockSecondaryIndexEntry>
§roots_tracker: RwLock<RootsTracker>
§ongoing_scan_roots: RwLock<BTreeMap<Slot, u64>>
§removed_bank_ids: Mutex<HashSet<BankId>>
§storage: AccountsIndexStorage<T, U>
§scan_results_limit_bytes: Option<usize>
when a scan’s accumulated data exceeds this limit, abort the scan
roots_added: AtomicUsize
§roots_removed: AtomicUsize
§active_scans: AtomicUsize
§max_distance_to_min_scan_slot: AtomicU64
§rent_paying_accounts_by_partition: OnceCell<RentPayingAccountsByPartition>
populated at generate_index time - accounts that could possibly be rent paying
Implementations§
source§impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> AccountsIndex<T, U>
impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> AccountsIndex<T, U>
pub fn default_for_tests() -> Self
pub fn new(config: Option<AccountsIndexConfig>, exit: &Arc<AtomicBool>) -> Self
fn allocate_accounts_index( config: Option<AccountsIndexConfig>, exit: &Arc<AtomicBool> ) -> (Vec<AccountMap<T, U>>, PubkeyBinCalculator24, AccountsIndexStorage<T, U>)
fn iter<R>( &self, range: Option<&R>, collect_all_unsorted: bool ) -> AccountsIndexIterator<'_, T, U> ⓘwhere R: RangeBounds<Pubkey>,
sourcepub fn is_disk_index_enabled(&self) -> bool
pub fn is_disk_index_enabled(&self) -> bool
is the accounts index using disk as a backing store
fn min_ongoing_scan_root_from_btree( ongoing_scan_roots: &BTreeMap<Slot, u64> ) -> Option<Slot>
fn do_checked_scan_accounts<F, R>( &self, metric_name: &'static str, ancestors: &Ancestors, scan_bank_id: BankId, func: F, scan_type: ScanTypes<R>, config: &ScanConfig ) -> Result<(), ScanError>where F: FnMut(&Pubkey, (&T, Slot)), R: RangeBounds<Pubkey> + Debug,
fn do_unchecked_scan_accounts<F, R>( &self, metric_name: &'static str, ancestors: &Ancestors, func: F, range: Option<R>, config: &ScanConfig )where F: FnMut(&Pubkey, (&T, Slot)), R: RangeBounds<Pubkey> + Debug,
fn do_scan_accounts<F, R>( &self, metric_name: &'static str, ancestors: &Ancestors, func: F, range: Option<R>, max_root: Option<Slot>, config: &ScanConfig )where F: FnMut(&Pubkey, (&T, Slot)), R: RangeBounds<Pubkey> + Debug,
fn do_scan_secondary_index<F, SecondaryIndexEntryType: SecondaryIndexEntry + Default + Sync + Send>( &self, ancestors: &Ancestors, func: F, index: &SecondaryIndex<SecondaryIndexEntryType>, index_key: &Pubkey, max_root: Option<Slot>, config: &ScanConfig )where F: FnMut(&Pubkey, (&T, Slot)),
pub fn get_account_read_entry( &self, pubkey: &Pubkey ) -> Option<ReadAccountMapEntry<T>>
pub fn get_account_read_entry_with_lock( &self, pubkey: &Pubkey, lock: &&'_ AccountMap<T, U> ) -> Option<ReadAccountMapEntry<T>>
fn slot_list_mut<RT>( &self, pubkey: &Pubkey, user: impl for<'a> FnOnce(&mut RwLockWriteGuard<'a, SlotList<T>>) -> RT ) -> Option<RT>
sourcepub fn handle_dead_keys(
&self,
dead_keys: &[&Pubkey],
account_indexes: &AccountSecondaryIndexes
) -> HashSet<Pubkey>
pub fn handle_dead_keys( &self, dead_keys: &[&Pubkey], account_indexes: &AccountSecondaryIndexes ) -> HashSet<Pubkey>
Remove keys from the account index if the key’s slot list is empty. Returns the keys that were removed from the index. These keys should not be accessed again in the current code path.
sourcepub(crate) fn scan_accounts<F>(
&self,
ancestors: &Ancestors,
scan_bank_id: BankId,
func: F,
config: &ScanConfig
) -> Result<(), ScanError>where
F: FnMut(&Pubkey, (&T, Slot)),
pub(crate) fn scan_accounts<F>( &self, ancestors: &Ancestors, scan_bank_id: BankId, func: F, config: &ScanConfig ) -> Result<(), ScanError>where F: FnMut(&Pubkey, (&T, Slot)),
call func with every pubkey and index visible from a given set of ancestors
pub(crate) fn unchecked_scan_accounts<F>( &self, metric_name: &'static str, ancestors: &Ancestors, func: F, config: &ScanConfig )where F: FnMut(&Pubkey, (&T, Slot)),
sourcepub(crate) fn range_scan_accounts<F, R>(
&self,
metric_name: &'static str,
ancestors: &Ancestors,
range: R,
config: &ScanConfig,
func: F
)where
F: FnMut(&Pubkey, (&T, Slot)),
R: RangeBounds<Pubkey> + Debug,
pub(crate) fn range_scan_accounts<F, R>( &self, metric_name: &'static str, ancestors: &Ancestors, range: R, config: &ScanConfig, func: F )where F: FnMut(&Pubkey, (&T, Slot)), R: RangeBounds<Pubkey> + Debug,
call func with every pubkey and index visible from a given set of ancestors with range Only guaranteed to be safe when called from rent collection
sourcepub(crate) fn index_scan_accounts<F>(
&self,
ancestors: &Ancestors,
scan_bank_id: BankId,
index_key: IndexKey,
func: F,
config: &ScanConfig
) -> Result<(), ScanError>where
F: FnMut(&Pubkey, (&T, Slot)),
pub(crate) fn index_scan_accounts<F>( &self, ancestors: &Ancestors, scan_bank_id: BankId, index_key: IndexKey, func: F, config: &ScanConfig ) -> Result<(), ScanError>where F: FnMut(&Pubkey, (&T, Slot)),
call func with every pubkey and index visible from a given set of ancestors
pub fn get_rooted_entries( &self, slice: SlotSlice<'_, T>, max_inclusive: Option<Slot> ) -> SlotList<T>
pub fn purge_exact<'a, C>( &'a self, pubkey: &Pubkey, slots_to_purge: &'a C, reclaims: &mut SlotList<T> ) -> boolwhere C: Contains<'a, Slot>,
pub fn min_ongoing_scan_root(&self) -> Option<Slot>
pub(crate) fn latest_slot( &self, ancestors: Option<&Ancestors>, slice: SlotSlice<'_, T>, max_root_inclusive: Option<Slot> ) -> Option<usize>
pub fn hold_range_in_memory<R>( &self, range: &R, start_holding: bool, thread_pool: &ThreadPool )where R: RangeBounds<Pubkey> + Debug + Sync,
pub fn set_startup(&self, value: Startup)
pub fn get_startup_remaining_items_to_flush_estimate(&self) -> usize
sourcepub(crate) fn scan<'a, F, I>(
&self,
pubkeys: I,
callback: F,
avoid_callback_result: Option<AccountsIndexScanResult>,
provide_entry_in_callback: bool
)where
F: FnMut(&'a Pubkey, Option<(&SlotList<T>, RefCount)>, Option<&Arc<AccountMapEntryInner<T>>>) -> AccountsIndexScanResult,
I: Iterator<Item = &'a Pubkey>,
pub(crate) fn scan<'a, F, I>( &self, pubkeys: I, callback: F, avoid_callback_result: Option<AccountsIndexScanResult>, provide_entry_in_callback: bool )where F: FnMut(&'a Pubkey, Option<(&SlotList<T>, RefCount)>, Option<&Arc<AccountMapEntryInner<T>>>) -> AccountsIndexScanResult, I: Iterator<Item = &'a Pubkey>,
For each pubkey, find the slot list in the accounts index
apply ‘avoid_callback_result’ if specified.
otherwise, call callback
if ‘provide_entry_in_callback’ is true, populate callback with the Arc of the entry itself.
sourcepub(crate) fn get(
&self,
pubkey: &Pubkey,
ancestors: Option<&Ancestors>,
max_root: Option<Slot>
) -> AccountIndexGetResult<T>
pub(crate) fn get( &self, pubkey: &Pubkey, ancestors: Option<&Ancestors>, max_root: Option<Slot> ) -> AccountIndexGetResult<T>
Get an account
The latest account that appears in ancestors
or roots
is returned.
fn get_newest_root_in_slot_list( alive_roots: &RollingBitField, slice: SlotSlice<'_, T>, max_allowed_root_inclusive: Option<Slot> ) -> Slot
fn update_spl_token_secondary_indexes<G: GenericTokenAccount>( &self, token_id: &Pubkey, pubkey: &Pubkey, account_owner: &Pubkey, account_data: &[u8], account_indexes: &AccountSecondaryIndexes )
pub fn get_index_key_size( &self, index: &AccountIndex, index_key: &Pubkey ) -> Option<usize>
pub fn get_largest_keys( &self, index: &AccountIndex, max_entries: usize ) -> Vec<(usize, Pubkey)>
sourcepub(crate) fn log_secondary_indexes(&self)
pub(crate) fn log_secondary_indexes(&self)
log any secondary index counts, if non-zero
pub(crate) fn update_secondary_indexes( &self, pubkey: &Pubkey, account: &impl ReadableAccount, account_indexes: &AccountSecondaryIndexes )
pub(crate) fn get_bin(&self, pubkey: &Pubkey) -> &'_ AccountMap<T, U>
pub fn bins(&self) -> usize
pub(crate) fn insert_new_if_missing_into_primary_index( &self, slot: Slot, item_len: usize, items: impl Iterator<Item = (Pubkey, T)> ) -> (Vec<Pubkey>, u64)
sourcepub(crate) fn populate_and_retrieve_duplicate_keys_from_startup(
&self
) -> Vec<Vec<(Slot, Pubkey)>>
pub(crate) fn populate_and_retrieve_duplicate_keys_from_startup( &self ) -> Vec<Vec<(Slot, Pubkey)>>
return Vec<Vec<>> because the internal vecs are already allocated per bin
sourcepub fn upsert(
&self,
new_slot: Slot,
old_slot: Slot,
pubkey: &Pubkey,
account: &impl ReadableAccount,
account_indexes: &AccountSecondaryIndexes,
account_info: T,
reclaims: &mut SlotList<T>,
reclaim: UpsertReclaim
)
pub fn upsert( &self, new_slot: Slot, old_slot: Slot, pubkey: &Pubkey, account: &impl ReadableAccount, account_indexes: &AccountSecondaryIndexes, account_info: T, reclaims: &mut SlotList<T>, reclaim: UpsertReclaim )
Updates the given pubkey at the given slot with the new account information. on return, the index’s previous account info may be returned in ‘reclaims’ depending on ‘previous_slot_entry_was_cached’
pub fn ref_count_from_storage(&self, pubkey: &Pubkey) -> RefCount
fn purge_secondary_indexes_by_inner_key( &self, inner_key: &Pubkey, account_indexes: &AccountSecondaryIndexes )
fn purge_older_root_entries( &self, slot_list: &mut SlotList<T>, reclaims: &mut SlotList<T>, max_clean_root_inclusive: Option<Slot> )
sourcepub fn clean_rooted_entries(
&self,
pubkey: &Pubkey,
reclaims: &mut SlotList<T>,
max_clean_root_inclusive: Option<Slot>
) -> bool
pub fn clean_rooted_entries( &self, pubkey: &Pubkey, reclaims: &mut SlotList<T>, max_clean_root_inclusive: Option<Slot> ) -> bool
return true if pubkey was removed from the accounts index or does not exist in the accounts index This means it should NOT be unref’d later.
sourcefn can_purge_older_entries(
max_clean_root_exclusive: Slot,
newest_root_in_slot_list: Slot,
slot: Slot
) -> bool
fn can_purge_older_entries( max_clean_root_exclusive: Slot, newest_root_in_slot_list: Slot, slot: Slot ) -> bool
When can an entry be purged?
If we get a slot update where slot != newest_root_in_slot_list for an account where slot < max_clean_root_exclusive, then we know it’s safe to delete because:
a) If slot < newest_root_in_slot_list, then we know the update is outdated by a later rooted update, namely the one in newest_root_in_slot_list
b) If slot > newest_root_in_slot_list, then because slot < max_clean_root_exclusive and we know there are no roots in the slot list between newest_root_in_slot_list and max_clean_root_exclusive, (otherwise there would be a bigger newest_root_in_slot_list, which is a contradiction), then we know slot must be an unrooted slot less than max_clean_root_exclusive and thus safe to clean as well.
sourcepub fn get_rooted_from_list<'a>(
&self,
slots: impl Iterator<Item = &'a Slot>
) -> Vec<Slot>
pub fn get_rooted_from_list<'a>( &self, slots: impl Iterator<Item = &'a Slot> ) -> Vec<Slot>
Given a list of slots, return a new list of only the slots that are rooted
pub fn is_alive_root(&self, slot: Slot) -> bool
pub fn add_root(&self, slot: Slot)
pub fn add_uncleaned_roots<I>(&self, roots: I)where I: IntoIterator<Item = Slot>,
pub fn max_root_inclusive(&self) -> Slot
sourcepub fn get_next_original_root(
&self,
slot: Slot,
ancestors: Option<&Ancestors>
) -> Option<Slot>
pub fn get_next_original_root( &self, slot: Slot, ancestors: Option<&Ancestors> ) -> Option<Slot>
return the lowest original root >= slot, including historical_roots and ancestors
sourcepub fn remove_old_historical_roots(
&self,
oldest_slot_to_keep: Slot,
keep: &HashSet<Slot>
)
pub fn remove_old_historical_roots( &self, oldest_slot_to_keep: Slot, keep: &HashSet<Slot> )
roots are inserted into ‘historical_roots’ and ‘roots’ as a new root is made. roots are removed form ‘roots’ as all entries in the append vec become outdated. This function exists to clean older entries from ‘historical_roots’. all roots < ‘oldest_slot_to_keep’ are removed from ‘historical_roots’.
sourcepub fn clean_dead_slot(
&self,
slot: Slot,
stats: &mut AccountsIndexRootsStats
) -> bool
pub fn clean_dead_slot( &self, slot: Slot, stats: &mut AccountsIndexRootsStats ) -> bool
Remove the slot when the storage for the slot is freed Accounts no longer reference this slot. return true if slot was a root