From e0c091a9f4f07faa52507881f57691492bdda43d Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Thu, 6 Jan 2022 10:49:24 -0600 Subject: [PATCH] factor out code in do_shrink_slot_stores (#22306) --- runtime/src/accounts_db.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index a29304981a..e0dba85124 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -2608,11 +2608,15 @@ impl AccountsDb { alive_total } - fn do_shrink_slot_stores<'a, I>(&'a self, slot: Slot, stores: I) -> usize + /// get all accounts in all the storages passed in + /// for duplicate pubkeys, the account with the highest write_value is returned + fn get_unique_accounts_from_storages<'a, I>( + &'a self, + stores: I, + ) -> (HashMap, usize, u64) where I: Iterator>, { - debug!("do_shrink_slot_stores: slot: {}", slot); let mut stored_accounts: HashMap = HashMap::new(); let mut original_bytes = 0; let mut num_stores = 0; @@ -2642,6 +2646,16 @@ impl AccountsDb { } num_stores += 1; } + (stored_accounts, num_stores, original_bytes) + } + + fn do_shrink_slot_stores<'a, I>(&'a self, slot: Slot, stores: I) -> usize + where + I: Iterator>, + { + debug!("do_shrink_slot_stores: slot: {}", slot); + let (stored_accounts, num_stores, original_bytes) = + self.get_unique_accounts_from_storages(stores); // sort by pubkey to keep account index lookups close let mut stored_accounts = stored_accounts.into_iter().collect::>();