From 100293c4b538f7f91b4065dea7842a6c9cbff187 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Thu, 6 Jan 2022 10:49:01 -0600 Subject: [PATCH] refactor get_store_for_shrink (#22307) --- runtime/src/accounts_db.rs | 50 +++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index e46514bea6..a29304981a 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -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, 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 {