refactor clean_dead_slots_from_accounts_index (#27451)

This commit is contained in:
Jeff Washington (jwash) 2022-08-30 10:06:52 -05:00 committed by GitHub
parent 73ee94d674
commit 3d692ba046
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 22 deletions

View File

@ -7577,6 +7577,37 @@ impl AccountsDb {
inc_new_counter_info!("remove_dead_slots_metadata-ms", measure.as_ms() as usize);
}
/// lookup each pubkey in 'purged_slot_pubkeys' and unref it in the accounts index
/// populate 'purged_stored_account_slots' by grouping 'purged_slot_pubkeys' by pubkey
fn unref_accounts(
&self,
purged_slot_pubkeys: HashSet<(Slot, Pubkey)>,
purged_stored_account_slots: &mut AccountSlots,
) {
let len = purged_slot_pubkeys.len();
const BATCH_SIZE: usize = 10_000;
let batches = 1 + (len / BATCH_SIZE);
self.thread_pool_clean.install(|| {
(0..batches).into_par_iter().for_each(|batch| {
let skip = batch * BATCH_SIZE;
self.accounts_index.scan(
purged_slot_pubkeys
.iter()
.skip(skip)
.take(BATCH_SIZE)
.map(|(_slot, pubkey)| pubkey),
|_pubkey, _slots_refs| AccountsIndexScanResult::Unref,
)
})
});
for (slot, pubkey) in purged_slot_pubkeys {
purged_stored_account_slots
.entry(pubkey)
.or_default()
.insert(slot);
}
}
fn clean_dead_slots_from_accounts_index<'a>(
&'a self,
dead_slots_iter: impl Iterator<Item = &'a Slot> + Clone,
@ -7587,28 +7618,7 @@ impl AccountsDb {
let mut accounts_index_root_stats = AccountsIndexRootsStats::default();
let mut measure = Measure::start("unref_from_storage");
if let Some(purged_stored_account_slots) = purged_stored_account_slots {
let len = purged_slot_pubkeys.len();
const BATCH_SIZE: usize = 10_000;
let batches = 1 + (len / BATCH_SIZE);
self.thread_pool_clean.install(|| {
(0..batches).into_par_iter().for_each(|batch| {
let skip = batch * BATCH_SIZE;
self.accounts_index.scan(
purged_slot_pubkeys
.iter()
.skip(skip)
.take(BATCH_SIZE)
.map(|(_slot, pubkey)| pubkey),
|_pubkey, _slots_refs| AccountsIndexScanResult::Unref,
)
})
});
for (slot, pubkey) in purged_slot_pubkeys {
purged_stored_account_slots
.entry(pubkey)
.or_default()
.insert(slot);
}
self.unref_accounts(purged_slot_pubkeys, purged_stored_account_slots);
}
measure.stop();
accounts_index_root_stats.clean_unref_from_storage_us += measure.as_us();