diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 416871c8d6..a4c40ca9c0 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -3715,26 +3715,32 @@ impl AccountsDb { } } - /// shared code for shrinking normal slots and combining into ancient append vecs - /// note 'stored_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, + fn get_unique_accounts_from_storage_for_shrink<'a>( + &self, store: &'a Arc, - stored_accounts: &'b mut Vec>, stats: &ShrinkStats, - ) -> ShrinkCollect<'b, T> { - let ( - GetUniqueAccountsResult { - stored_accounts: stored_accounts_temp, - original_bytes, - }, - storage_read_elapsed, - ) = measure!(self.get_unique_accounts_from_storage(store)); - let slot = store.slot(); + ) -> GetUniqueAccountsResult<'a> { + let (result, storage_read_elapsed) = measure!(self.get_unique_accounts_from_storage(store)); stats .storage_read_elapsed .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, + 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"); @@ -3794,7 +3800,7 @@ impl AccountsDb { .fetch_add(aligned_total_bytes, Ordering::Relaxed); ShrinkCollect { - original_bytes, + original_bytes: *original_bytes, aligned_total_bytes, unrefed_pubkeys, 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. 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); - let shrink_collect = self.shrink_collect::>( - store, - &mut stored_accounts, - &self.shrink_stats, - ); + let shrink_collect = + self.shrink_collect::>(store, &unique_accounts, &self.shrink_stats); // This shouldn't happen if alive_bytes/approx_stored_count are accurate if Self::should_not_shrink( @@ -4409,10 +4413,13 @@ impl AccountsDb { ancient_slot_pubkeys: &mut AncientSlotPubkeys, dropped_roots: &mut Vec, ) { - 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::>( old_storage, - &mut stored_accounts, + &unique_accounts, &self.shrink_ancient_stats.shrink_stats, ); @@ -16759,10 +16766,15 @@ pub mod tests { }); 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::>( &storage, - &mut stored_accounts, + &unique_accounts, &ShrinkStats::default(), ); let expect_single_opposite_alive_account =