diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 6be6fd8d5b..f851b4d0b3 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -2835,18 +2835,7 @@ impl AccountsDb { // Purge old, overwritten storage entries let mut start = Measure::start("write_storage_elapsed"); - if let Some(slot_stores) = self.storage.get_slot_stores(slot) { - slot_stores.write().unwrap().retain(|_key, store| { - if store.count() == 0 { - self.dirty_stores - .insert((slot, store.append_vec_id()), store.clone()); - dead_storages.push(store.clone()); - false - } else { - true - } - }); - } + self.mark_dirty_dead_stores(slot, &mut dead_storages, |store| store.count() > 0); start.stop(); write_storage_elapsed = start.as_us(); } @@ -2901,6 +2890,29 @@ impl AccountsDb { total_accounts_after_shrink } + /// get stores for 'slot' + /// retain only the stores where 'should_retain(store)' == true + /// for stores not retained, insert in 'dirty_stores' and 'dead_storages' + fn mark_dirty_dead_stores( + &self, + slot: Slot, + dead_storages: &mut Vec>, + should_retain: impl Fn(&AccountStorageEntry) -> bool, + ) { + if let Some(slot_stores) = self.storage.get_slot_stores(slot) { + slot_stores.write().unwrap().retain(|_key, store| { + if !should_retain(store) { + self.dirty_stores + .insert((slot, store.append_vec_id()), store.clone()); + dead_storages.push(store.clone()); + false + } else { + true + } + }); + } + } + fn drop_or_recycle_stores(&self, dead_storages: Vec>) { let mut recycle_stores_write_elapsed = Measure::start("recycle_stores_write_time"); let mut recycle_stores = self.recycle_stores.write().unwrap();