refactor get_store_for_shrink (#22307)

This commit is contained in:
Jeff Washington (jwash) 2022-01-06 10:49:01 -06:00 committed by GitHub
parent 705084a25b
commit 100293c4b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 30 additions and 20 deletions

View File

@ -2736,26 +2736,8 @@ impl AccountsDb {
start.stop();
find_alive_elapsed = start.as_us();
let mut start = Measure::start("create_and_insert_store_elapsed");
let shrunken_store = if let Some(new_store) =
self.try_recycle_and_insert_store(slot, aligned_total, aligned_total + 1024)
{
new_store
} else {
let maybe_shrink_paths = self.shrink_paths.read().unwrap();
if let Some(ref shrink_paths) = *maybe_shrink_paths {
self.create_and_insert_store_with_paths(
slot,
aligned_total,
"shrink-w-path",
shrink_paths,
)
} else {
self.create_and_insert_store(slot, aligned_total, "shrink")
}
};
start.stop();
create_and_insert_store_elapsed = start.as_us();
let (shrunken_store, time) = self.get_store_for_shrink(slot, aligned_total);
create_and_insert_store_elapsed = time;
// here, we're writing back alive_accounts. That should be an atomic operation
// without use of rather wide locks in this whole function, because we're
@ -2864,6 +2846,34 @@ impl AccountsDb {
total_accounts_after_shrink
}
/// return a store that can contain 'aligned_total' bytes and the time it took to execute
fn get_store_for_shrink(
&self,
slot: Slot,
aligned_total: u64,
) -> (Arc<AccountStorageEntry>, u64) {
let mut start = Measure::start("create_and_insert_store_elapsed");
let shrunken_store = if let Some(new_store) =
self.try_recycle_and_insert_store(slot, aligned_total, aligned_total + 1024)
{
new_store
} else {
let maybe_shrink_paths = self.shrink_paths.read().unwrap();
if let Some(ref shrink_paths) = *maybe_shrink_paths {
self.create_and_insert_store_with_paths(
slot,
aligned_total,
"shrink-w-path",
shrink_paths,
)
} else {
self.create_and_insert_store(slot, aligned_total, "shrink")
}
};
start.stop();
(shrunken_store, start.as_us())
}
// Reads all accounts in given slot's AppendVecs and filter only to alive,
// then create a minimum AppendVec filled with the alive.
fn shrink_slot_forced(&self, slot: Slot) -> usize {