From 91ccab30354cb8522de4e6e3bd4dce1ccde8a907 Mon Sep 17 00:00:00 2001 From: Brooks Date: Thu, 14 Nov 2024 17:55:44 -0500 Subject: [PATCH] Refactors cached_frozen_slots() (#3644) --- accounts-db/src/accounts_cache.rs | 13 +++---------- accounts-db/src/accounts_db.rs | 3 ++- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/accounts-db/src/accounts_cache.rs b/accounts-db/src/accounts_cache.rs index 8a9be3b014ce39..ffe9a4351adaf4 100644 --- a/accounts-db/src/accounts_cache.rs +++ b/accounts-db/src/accounts_cache.rs @@ -259,20 +259,13 @@ impl AccountsCache { } pub fn cached_frozen_slots(&self) -> Vec { - let mut slots: Vec<_> = self - .cache + self.cache .iter() .filter_map(|item| { let (slot, slot_cache) = item.pair(); - if slot_cache.is_frozen() { - Some(*slot) - } else { - None - } + slot_cache.is_frozen().then_some(*slot) }) - .collect(); - slots.sort_unstable(); - slots + .collect() } pub fn contains(&self, slot: Slot) -> bool { diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index 3c999bab81c6d7..2616ab9d6d30b3 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -6172,7 +6172,8 @@ impl AccountsDb { let mut unflushable_unrooted_slot_count = 0; let max_flushed_root = self.accounts_cache.fetch_max_flush_root(); if self.should_aggressively_flush_cache() { - let old_slots = self.accounts_cache.cached_frozen_slots(); + let mut old_slots = self.accounts_cache.cached_frozen_slots(); + old_slots.sort_unstable(); excess_slot_count = old_slots.len(); let mut flush_stats = FlushStats::default(); old_slots.into_iter().for_each(|old_slot| {