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::*,
|
secondary_index::*,
|
||||||
},
|
},
|
||||||
log::*,
|
log::*,
|
||||||
|
once_cell::sync::OnceCell,
|
||||||
ouroboros::self_referencing,
|
ouroboros::self_referencing,
|
||||||
rand::{thread_rng, Rng},
|
rand::{thread_rng, Rng},
|
||||||
rayon::{
|
rayon::{
|
||||||
|
@ -697,7 +698,7 @@ pub struct AccountsIndex<T: IndexValue> {
|
||||||
pub max_distance_to_min_scan_slot: AtomicU64,
|
pub max_distance_to_min_scan_slot: AtomicU64,
|
||||||
|
|
||||||
/// populated at generate_index time - accounts that could possibly be rent paying
|
/// 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> {
|
impl<T: IndexValue> AccountsIndex<T> {
|
||||||
|
@ -731,7 +732,7 @@ impl<T: IndexValue> AccountsIndex<T> {
|
||||||
roots_removed: AtomicUsize::default(),
|
roots_removed: AtomicUsize::default(),
|
||||||
active_scans: AtomicUsize::default(),
|
active_scans: AtomicUsize::default(),
|
||||||
max_distance_to_min_scan_slot: AtomicU64::default(),
|
max_distance_to_min_scan_slot: AtomicU64::default(),
|
||||||
rent_paying_accounts_by_partition: RwLock::default(),
|
rent_paying_accounts_by_partition: OnceCell::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5456,23 +5456,23 @@ 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)
|
/// 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>> {
|
fn get_rent_paying_pubkeys(&self, partition: &Partition) -> Option<HashSet<Pubkey>> {
|
||||||
let rent_paying_accounts = &self
|
self.rc
|
||||||
.rc
|
|
||||||
.accounts
|
.accounts
|
||||||
.accounts_db
|
.accounts_db
|
||||||
.accounts_index
|
.accounts_index
|
||||||
.rent_paying_accounts_by_partition
|
.rent_paying_accounts_by_partition
|
||||||
.read()
|
.get()
|
||||||
.unwrap();
|
.and_then(|rent_paying_accounts| {
|
||||||
rent_paying_accounts.is_initialized().then(|| {
|
rent_paying_accounts.is_initialized().then(|| {
|
||||||
Self::get_partition_end_indexes(partition)
|
Self::get_partition_end_indexes(partition)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(|end_index| {
|
.flat_map(|end_index| {
|
||||||
rent_paying_accounts.get_pubkeys_in_partition_index(end_index)
|
rent_paying_accounts.get_pubkeys_in_partition_index(end_index)
|
||||||
|
})
|
||||||
|
.cloned()
|
||||||
|
.collect::<HashSet<_>>()
|
||||||
})
|
})
|
||||||
.cloned()
|
})
|
||||||
.collect::<HashSet<_>>()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// load accounts with pubkeys in 'subrange_full'
|
/// 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(&pk1);
|
||||||
rent_paying_accounts_by_partition.add_account(&pk2);
|
rent_paying_accounts_by_partition.add_account(&pk2);
|
||||||
|
|
||||||
*bank
|
bank.rc
|
||||||
.rc
|
|
||||||
.accounts
|
.accounts
|
||||||
.accounts_db
|
.accounts_db
|
||||||
.accounts_index
|
.accounts_index
|
||||||
.rent_paying_accounts_by_partition
|
.rent_paying_accounts_by_partition
|
||||||
.write()
|
.set(rent_paying_accounts_by_partition)
|
||||||
.unwrap() = rent_paying_accounts_by_partition;
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.get_rent_paying_pubkeys(&(0, 1, n)),
|
bank.get_rent_paying_pubkeys(&(0, 1, n)),
|
||||||
|
|
|
@ -722,11 +722,11 @@ where
|
||||||
verify_index,
|
verify_index,
|
||||||
genesis_config,
|
genesis_config,
|
||||||
);
|
);
|
||||||
*accounts_db
|
accounts_db
|
||||||
.accounts_index
|
.accounts_index
|
||||||
.rent_paying_accounts_by_partition
|
.rent_paying_accounts_by_partition
|
||||||
.write()
|
.set(rent_paying_accounts_by_partition)
|
||||||
.unwrap() = rent_paying_accounts_by_partition;
|
.unwrap();
|
||||||
|
|
||||||
accounts_db.maybe_add_filler_accounts(
|
accounts_db.maybe_add_filler_accounts(
|
||||||
&genesis_config.epoch_schedule,
|
&genesis_config.epoch_schedule,
|
||||||
|
|
Loading…
Reference in New Issue