refactor shrink_collect (#29982)
* refactor shrink_collect * Update runtime/src/accounts_db.rs Co-authored-by: Andrew Fitzgerald <apfitzge@gmail.com> --------- Co-authored-by: Andrew Fitzgerald <apfitzge@gmail.com>
This commit is contained in:
parent
3e5ab0437f
commit
8a56a856d8
|
@ -3715,26 +3715,32 @@ impl AccountsDb {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// shared code for shrinking normal slots and combining into ancient append vecs
|
fn get_unique_accounts_from_storage_for_shrink<'a>(
|
||||||
/// note 'stored_accounts' is passed by ref so we can return references to data within it, avoiding self-references
|
&self,
|
||||||
fn shrink_collect<'a: 'b, 'b, T: ShrinkCollectRefs<'b>>(
|
|
||||||
&'a self,
|
|
||||||
store: &'a Arc<AccountStorageEntry>,
|
store: &'a Arc<AccountStorageEntry>,
|
||||||
stored_accounts: &'b mut Vec<StoredAccountMeta<'b>>,
|
|
||||||
stats: &ShrinkStats,
|
stats: &ShrinkStats,
|
||||||
) -> ShrinkCollect<'b, T> {
|
) -> GetUniqueAccountsResult<'a> {
|
||||||
let (
|
let (result, storage_read_elapsed) = measure!(self.get_unique_accounts_from_storage(store));
|
||||||
GetUniqueAccountsResult {
|
|
||||||
stored_accounts: stored_accounts_temp,
|
|
||||||
original_bytes,
|
|
||||||
},
|
|
||||||
storage_read_elapsed,
|
|
||||||
) = measure!(self.get_unique_accounts_from_storage(store));
|
|
||||||
let slot = store.slot();
|
|
||||||
stats
|
stats
|
||||||
.storage_read_elapsed
|
.storage_read_elapsed
|
||||||
.fetch_add(storage_read_elapsed.as_us(), Ordering::Relaxed);
|
.fetch_add(storage_read_elapsed.as_us(), Ordering::Relaxed);
|
||||||
*stored_accounts = stored_accounts_temp;
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
/// shared code for shrinking normal slots and combining into ancient append vecs
|
||||||
|
/// note 'unique_accounts' is passed by ref so we can return references to data within it, avoiding self-references
|
||||||
|
fn shrink_collect<'a: 'b, 'b, T: ShrinkCollectRefs<'b>>(
|
||||||
|
&'a self,
|
||||||
|
store: &'a Arc<AccountStorageEntry>,
|
||||||
|
unique_accounts: &'b GetUniqueAccountsResult<'b>,
|
||||||
|
stats: &ShrinkStats,
|
||||||
|
) -> ShrinkCollect<'b, T> {
|
||||||
|
let slot = store.slot();
|
||||||
|
|
||||||
|
let GetUniqueAccountsResult {
|
||||||
|
stored_accounts,
|
||||||
|
original_bytes,
|
||||||
|
} = unique_accounts;
|
||||||
|
|
||||||
let mut index_read_elapsed = Measure::start("index_read_elapsed");
|
let mut index_read_elapsed = Measure::start("index_read_elapsed");
|
||||||
|
|
||||||
|
@ -3794,7 +3800,7 @@ impl AccountsDb {
|
||||||
.fetch_add(aligned_total_bytes, Ordering::Relaxed);
|
.fetch_add(aligned_total_bytes, Ordering::Relaxed);
|
||||||
|
|
||||||
ShrinkCollect {
|
ShrinkCollect {
|
||||||
original_bytes,
|
original_bytes: *original_bytes,
|
||||||
aligned_total_bytes,
|
aligned_total_bytes,
|
||||||
unrefed_pubkeys,
|
unrefed_pubkeys,
|
||||||
alive_accounts,
|
alive_accounts,
|
||||||
|
@ -3847,13 +3853,11 @@ impl AccountsDb {
|
||||||
// It is 'correct' to ignore calls to shrink when a slot is still in the write cache.
|
// It is 'correct' to ignore calls to shrink when a slot is still in the write cache.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let mut stored_accounts = Vec::default();
|
let unique_accounts =
|
||||||
|
self.get_unique_accounts_from_storage_for_shrink(store, &self.shrink_stats);
|
||||||
debug!("do_shrink_slot_store: slot: {}", slot);
|
debug!("do_shrink_slot_store: slot: {}", slot);
|
||||||
let shrink_collect = self.shrink_collect::<AliveAccounts<'_>>(
|
let shrink_collect =
|
||||||
store,
|
self.shrink_collect::<AliveAccounts<'_>>(store, &unique_accounts, &self.shrink_stats);
|
||||||
&mut stored_accounts,
|
|
||||||
&self.shrink_stats,
|
|
||||||
);
|
|
||||||
|
|
||||||
// This shouldn't happen if alive_bytes/approx_stored_count are accurate
|
// This shouldn't happen if alive_bytes/approx_stored_count are accurate
|
||||||
if Self::should_not_shrink(
|
if Self::should_not_shrink(
|
||||||
|
@ -4409,10 +4413,13 @@ impl AccountsDb {
|
||||||
ancient_slot_pubkeys: &mut AncientSlotPubkeys,
|
ancient_slot_pubkeys: &mut AncientSlotPubkeys,
|
||||||
dropped_roots: &mut Vec<Slot>,
|
dropped_roots: &mut Vec<Slot>,
|
||||||
) {
|
) {
|
||||||
let mut stored_accounts = Vec::default();
|
let unique_accounts = self.get_unique_accounts_from_storage_for_shrink(
|
||||||
|
old_storage,
|
||||||
|
&self.shrink_ancient_stats.shrink_stats,
|
||||||
|
);
|
||||||
let shrink_collect = self.shrink_collect::<AliveAccounts<'_>>(
|
let shrink_collect = self.shrink_collect::<AliveAccounts<'_>>(
|
||||||
old_storage,
|
old_storage,
|
||||||
&mut stored_accounts,
|
&unique_accounts,
|
||||||
&self.shrink_ancient_stats.shrink_stats,
|
&self.shrink_ancient_stats.shrink_stats,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -16759,10 +16766,15 @@ pub mod tests {
|
||||||
});
|
});
|
||||||
|
|
||||||
let storage = db.get_storage_for_slot(slot5).unwrap();
|
let storage = db.get_storage_for_slot(slot5).unwrap();
|
||||||
let mut stored_accounts = Vec::default();
|
let unique_accounts = db
|
||||||
|
.get_unique_accounts_from_storage_for_shrink(
|
||||||
|
&storage,
|
||||||
|
&ShrinkStats::default(),
|
||||||
|
);
|
||||||
|
|
||||||
let shrink_collect = db.shrink_collect::<AliveAccounts<'_>>(
|
let shrink_collect = db.shrink_collect::<AliveAccounts<'_>>(
|
||||||
&storage,
|
&storage,
|
||||||
&mut stored_accounts,
|
&unique_accounts,
|
||||||
&ShrinkStats::default(),
|
&ShrinkStats::default(),
|
||||||
);
|
);
|
||||||
let expect_single_opposite_alive_account =
|
let expect_single_opposite_alive_account =
|
||||||
|
|
Loading…
Reference in New Issue