diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 889d856b77..f4970026de 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -38,8 +38,8 @@ use { }, accounts_index::{ AccountIndexGetResult, AccountSecondaryIndexes, AccountsIndex, AccountsIndexConfig, - AccountsIndexRootsStats, AccountsIndexScanResult, IndexKey, IndexValue, IsCached, - RefCount, ScanConfig, ScanResult, SlotList, UpsertReclaim, ZeroLamport, + AccountsIndexRootsStats, AccountsIndexScanResult, DiskIndexValue, IndexKey, IndexValue, + IsCached, RefCount, ScanConfig, ScanResult, SlotList, UpsertReclaim, ZeroLamport, ACCOUNTS_INDEX_CONFIG_FOR_BENCHMARKS, ACCOUNTS_INDEX_CONFIG_FOR_TESTING, }, accounts_index_storage::Startup, @@ -676,6 +676,7 @@ impl GenerateIndexTimings { } impl IndexValue for AccountInfo {} +impl DiskIndexValue for AccountInfo {} impl ZeroLamport for AccountSharedData { fn is_zero_lamport(&self) -> bool { diff --git a/runtime/src/accounts_index.rs b/runtime/src/accounts_index.rs index edc8909aac..0e150a3849 100644 --- a/runtime/src/accounts_index.rs +++ b/runtime/src/accounts_index.rs @@ -133,8 +133,10 @@ pub trait IsCached { fn is_cached(&self) -> bool; } -pub trait IndexValue: - 'static + IsCached + Clone + Debug + PartialEq + ZeroLamport + Copy + Default + Sync + Send +pub trait IndexValue: 'static + IsCached + ZeroLamport + DiskIndexValue {} + +pub trait DiskIndexValue: + 'static + Clone + Debug + PartialEq + Copy + Default + Sync + Send { } @@ -232,7 +234,7 @@ pub struct AccountMapEntryMeta { } impl AccountMapEntryMeta { - pub fn new_dirty + Into>( + pub fn new_dirty + Into>( storage: &Arc>, is_cached: bool, ) -> Self { @@ -241,7 +243,7 @@ impl AccountMapEntryMeta { age: AtomicU8::new(storage.future_age_to_flush(is_cached)), } } - pub fn new_clean + Into>( + pub fn new_clean + Into>( storage: &Arc>, ) -> Self { AccountMapEntryMeta { @@ -402,7 +404,7 @@ impl PreAllocatedAccountMapEntry { /// 1. new empty (refcount=0, slot_list={}) /// 2. update(slot, account_info) /// This code is called when the first entry [ie. (slot,account_info)] for a pubkey is inserted into the index. - pub fn new + Into>( + pub fn new + Into>( slot: Slot, account_info: T, storage: &Arc>, @@ -415,7 +417,7 @@ impl PreAllocatedAccountMapEntry { } } - fn allocate + Into>( + fn allocate + Into>( slot: Slot, account_info: T, storage: &Arc>, @@ -430,7 +432,7 @@ impl PreAllocatedAccountMapEntry { )) } - pub fn into_account_map_entry + Into>( + pub fn into_account_map_entry + Into>( self, storage: &Arc>, ) -> AccountMapEntry { @@ -495,7 +497,7 @@ pub struct AccountsIndexRootsStats { pub clean_dead_slot_us: u64, } -pub struct AccountsIndexIterator<'a, T: IndexValue, U: IndexValue + From + Into> { +pub struct AccountsIndexIterator<'a, T: IndexValue, U: DiskIndexValue + From + Into> { account_maps: &'a LockMapTypeSlice, bin_calculator: &'a PubkeyBinCalculator24, start_bound: Bound, @@ -504,7 +506,7 @@ pub struct AccountsIndexIterator<'a, T: IndexValue, U: IndexValue + From + In collect_all_unsorted: bool, } -impl<'a, T: IndexValue, U: IndexValue + From + Into> AccountsIndexIterator<'a, T, U> { +impl<'a, T: IndexValue, U: DiskIndexValue + From + Into> AccountsIndexIterator<'a, T, U> { fn range( map: &AccountMaps, range: R, @@ -604,7 +606,7 @@ impl<'a, T: IndexValue, U: IndexValue + From + Into> AccountsIndexIterator } } -impl<'a, T: IndexValue, U: IndexValue + From + Into> Iterator +impl<'a, T: IndexValue, U: DiskIndexValue + From + Into> Iterator for AccountsIndexIterator<'a, T, U> { type Item = Vec<(Pubkey, AccountMapEntry)>; @@ -677,7 +679,7 @@ pub enum AccountsIndexScanResult { #[derive(Debug)] /// T: account info type to interact in in-memory items /// U: account info type to be persisted to disk -pub struct AccountsIndex + Into> { +pub struct AccountsIndex + Into> { pub account_maps: LockMapType, pub bin_calculator: PubkeyBinCalculator24, program_id_index: SecondaryIndex, @@ -715,7 +717,7 @@ pub struct AccountsIndex + Into> { pub rent_paying_accounts_by_partition: OnceCell, } -impl + Into> AccountsIndex { +impl + Into> AccountsIndex { pub fn default_for_tests() -> Self { Self::new(Some(ACCOUNTS_INDEX_CONFIG_FOR_TESTING), &Arc::default()) } @@ -2144,7 +2146,7 @@ pub mod tests { } } - impl AccountsIndex { + impl + Into> AccountsIndex { /// provides the ability to refactor this function on the api without bloody changes pub fn get_for_tests( &self, @@ -2416,6 +2418,7 @@ pub mod tests { type AccountInfoTest = f64; impl IndexValue for AccountInfoTest {} + impl DiskIndexValue for AccountInfoTest {} impl IsCached for AccountInfoTest { fn is_cached(&self) -> bool { true @@ -3930,6 +3933,8 @@ pub mod tests { impl IndexValue for bool {} impl IndexValue for u64 {} + impl DiskIndexValue for bool {} + impl DiskIndexValue for u64 {} impl IsCached for bool { fn is_cached(&self) -> bool { false diff --git a/runtime/src/accounts_index_storage.rs b/runtime/src/accounts_index_storage.rs index c3db58a16b..01d32202af 100644 --- a/runtime/src/accounts_index_storage.rs +++ b/runtime/src/accounts_index_storage.rs @@ -1,6 +1,6 @@ use { crate::{ - accounts_index::{AccountsIndexConfig, IndexValue}, + accounts_index::{AccountsIndexConfig, DiskIndexValue, IndexValue}, bucket_map_holder::BucketMapHolder, in_mem_accounts_index::InMemAccountsIndex, waitable_condvar::WaitableCondvar, @@ -16,7 +16,7 @@ use { }; /// Manages the lifetime of the background processing threads. -pub struct AccountsIndexStorage + Into> { +pub struct AccountsIndexStorage + Into> { _bg_threads: BgThreads, pub storage: Arc>, @@ -27,7 +27,7 @@ pub struct AccountsIndexStorage + Into startup_worker_threads: Mutex>, } -impl + Into> Debug for AccountsIndexStorage { +impl + Into> Debug for AccountsIndexStorage { fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { Ok(()) } @@ -53,7 +53,7 @@ impl Drop for BgThreads { } impl BgThreads { - fn new + Into>( + fn new + Into>( storage: &Arc>, in_mem: &[Arc>], threads: usize, @@ -109,7 +109,7 @@ pub enum Startup { StartupWithExtraThreads, } -impl + Into> AccountsIndexStorage { +impl + Into> AccountsIndexStorage { /// startup=true causes: /// in mem to act in a way that flushes to disk asap /// also creates some additional bg threads to facilitate flushing to disk asap diff --git a/runtime/src/bucket_map_holder.rs b/runtime/src/bucket_map_holder.rs index bca6cf9b69..aca0b0e57a 100644 --- a/runtime/src/bucket_map_holder.rs +++ b/runtime/src/bucket_map_holder.rs @@ -1,6 +1,6 @@ use { crate::{ - accounts_index::{AccountsIndexConfig, IndexLimitMb, IndexValue}, + accounts_index::{AccountsIndexConfig, DiskIndexValue, IndexLimitMb, IndexValue}, bucket_map_holder_stats::BucketMapHolderStats, in_mem_accounts_index::InMemAccountsIndex, waitable_condvar::WaitableCondvar, @@ -28,7 +28,7 @@ const AGE_MS: u64 = DEFAULT_MS_PER_SLOT; // match one age per slot time // 10 GB limit for in-mem idx. In practice, we don't get this high. This tunes how aggressively to save items we expect to use soon. pub const DEFAULT_DISK_INDEX: Option = Some(10_000); -pub struct BucketMapHolder + Into> { +pub struct BucketMapHolder + Into> { pub disk: Option>, pub count_buckets_flushed: AtomicUsize, @@ -70,14 +70,14 @@ pub struct BucketMapHolder + Into> { _phantom: PhantomData, } -impl + Into> Debug for BucketMapHolder { +impl + Into> Debug for BucketMapHolder { fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { Ok(()) } } #[allow(clippy::mutex_atomic)] -impl + Into> BucketMapHolder { +impl + Into> BucketMapHolder { /// is the accounts index using disk as a backing store pub fn is_disk_index_enabled(&self) -> bool { self.disk.is_some() diff --git a/runtime/src/bucket_map_holder_stats.rs b/runtime/src/bucket_map_holder_stats.rs index 2d574558b6..89b0ab6bce 100644 --- a/runtime/src/bucket_map_holder_stats.rs +++ b/runtime/src/bucket_map_holder_stats.rs @@ -1,5 +1,8 @@ use { - crate::{accounts_index::IndexValue, bucket_map_holder::BucketMapHolder}, + crate::{ + accounts_index::{DiskIndexValue, IndexValue}, + bucket_map_holder::BucketMapHolder, + }, solana_sdk::timing::AtomicInterval, std::{ fmt::Debug, @@ -99,7 +102,7 @@ impl BucketMapHolderStats { per_bucket.map(|stat| stat.fetch_sub(count, Ordering::Relaxed)); } - fn ms_per_age + Into>( + fn ms_per_age + Into>( &self, storage: &BucketMapHolder, elapsed_ms: u64, @@ -176,7 +179,7 @@ impl BucketMapHolderStats { in_mem.saturating_sub(held_in_mem) as usize } - pub fn report_stats + Into>( + pub fn report_stats + Into>( &self, storage: &BucketMapHolder, ) { diff --git a/runtime/src/in_mem_accounts_index.rs b/runtime/src/in_mem_accounts_index.rs index cc04c11ca5..b489bc23d0 100644 --- a/runtime/src/in_mem_accounts_index.rs +++ b/runtime/src/in_mem_accounts_index.rs @@ -1,7 +1,7 @@ use { crate::{ accounts_index::{ - AccountMapEntry, AccountMapEntryInner, AccountMapEntryMeta, IndexValue, + AccountMapEntry, AccountMapEntryInner, AccountMapEntryMeta, DiskIndexValue, IndexValue, PreAllocatedAccountMapEntry, RefCount, SlotList, UpsertReclaim, ZeroLamport, }, bucket_map_holder::{Age, BucketMapHolder}, @@ -83,7 +83,7 @@ impl PossibleEvictions { } // one instance of this represents one bin of the accounts index. -pub struct InMemAccountsIndex + Into> { +pub struct InMemAccountsIndex + Into> { last_age_flushed: AtomicU8, // backing store @@ -112,7 +112,7 @@ pub struct InMemAccountsIndex + Into> age_to_flush_bin_mod: Age, } -impl + Into> Debug for InMemAccountsIndex { +impl + Into> Debug for InMemAccountsIndex { fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { Ok(()) } @@ -141,7 +141,7 @@ struct FlushScanResult { evictions_random: Vec<(Pubkey, AccountMapEntry)>, } -impl + Into> InMemAccountsIndex { +impl + Into> InMemAccountsIndex { pub fn new(storage: &Arc>, bin: usize) -> Self { let ages_to_stay_in_cache = storage.ages_to_stay_in_cache; Self { @@ -1397,7 +1397,7 @@ struct EvictionsGuard<'a> { impl<'a> EvictionsGuard<'a> { #[must_use = "if unused, this evictions lock will be immediately unlocked"] - fn lock + Into>( + fn lock + Into>( in_mem_accounts_index: &'a InMemAccountsIndex, ) -> Self { Self::lock_with(