use OnceCell instead of RwLock for rent_paying_accounts_by_partition (#26601)
This commit is contained in:
parent
1bc2cc7f76
commit
3e9bd6170c
|
@ -13,6 +13,7 @@ use {
|
|||
secondary_index::*,
|
||||
},
|
||||
log::*,
|
||||
once_cell::sync::OnceCell,
|
||||
ouroboros::self_referencing,
|
||||
rand::{thread_rng, Rng},
|
||||
rayon::{
|
||||
|
@ -697,7 +698,7 @@ pub struct AccountsIndex<T: IndexValue> {
|
|||
pub max_distance_to_min_scan_slot: AtomicU64,
|
||||
|
||||
/// populated at generate_index time - accounts that could possibly be rent paying
|
||||
pub rent_paying_accounts_by_partition: RwLock<RentPayingAccountsByPartition>,
|
||||
pub rent_paying_accounts_by_partition: OnceCell<RentPayingAccountsByPartition>,
|
||||
}
|
||||
|
||||
impl<T: IndexValue> AccountsIndex<T> {
|
||||
|
@ -731,7 +732,7 @@ impl<T: IndexValue> AccountsIndex<T> {
|
|||
roots_removed: AtomicUsize::default(),
|
||||
active_scans: AtomicUsize::default(),
|
||||
max_distance_to_min_scan_slot: AtomicU64::default(),
|
||||
rent_paying_accounts_by_partition: RwLock::default(),
|
||||
rent_paying_accounts_by_partition: OnceCell::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5456,14 +5456,13 @@ impl Bank {
|
|||
|
||||
/// get all pubkeys that we expect to be rent-paying or None, if this was not initialized at load time (that should only exist in test cases)
|
||||
fn get_rent_paying_pubkeys(&self, partition: &Partition) -> Option<HashSet<Pubkey>> {
|
||||
let rent_paying_accounts = &self
|
||||
.rc
|
||||
self.rc
|
||||
.accounts
|
||||
.accounts_db
|
||||
.accounts_index
|
||||
.rent_paying_accounts_by_partition
|
||||
.read()
|
||||
.unwrap();
|
||||
.get()
|
||||
.and_then(|rent_paying_accounts| {
|
||||
rent_paying_accounts.is_initialized().then(|| {
|
||||
Self::get_partition_end_indexes(partition)
|
||||
.into_iter()
|
||||
|
@ -5473,6 +5472,7 @@ impl Bank {
|
|||
.cloned()
|
||||
.collect::<HashSet<_>>()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/// load accounts with pubkeys in 'subrange_full'
|
||||
|
@ -19322,14 +19322,13 @@ pub(crate) mod tests {
|
|||
rent_paying_accounts_by_partition.add_account(&pk1);
|
||||
rent_paying_accounts_by_partition.add_account(&pk2);
|
||||
|
||||
*bank
|
||||
.rc
|
||||
bank.rc
|
||||
.accounts
|
||||
.accounts_db
|
||||
.accounts_index
|
||||
.rent_paying_accounts_by_partition
|
||||
.write()
|
||||
.unwrap() = rent_paying_accounts_by_partition;
|
||||
.set(rent_paying_accounts_by_partition)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
bank.get_rent_paying_pubkeys(&(0, 1, n)),
|
||||
|
|
|
@ -722,11 +722,11 @@ where
|
|||
verify_index,
|
||||
genesis_config,
|
||||
);
|
||||
*accounts_db
|
||||
accounts_db
|
||||
.accounts_index
|
||||
.rent_paying_accounts_by_partition
|
||||
.write()
|
||||
.unwrap() = rent_paying_accounts_by_partition;
|
||||
.set(rent_paying_accounts_by_partition)
|
||||
.unwrap();
|
||||
|
||||
accounts_db.maybe_add_filler_accounts(
|
||||
&genesis_config.epoch_schedule,
|
||||
|
|
Loading…
Reference in New Issue