Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
add test and comments (#29459)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington authored Jan 2, 2023
1 parent 67c7e34 commit 38d771a
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4027,11 +4027,14 @@ impl AccountsDb {

let remaining_stores = if let Some(slot_stores) = self.storage.get_slot_stores(slot) {
if let Some(shrink_in_progress) = shrink_in_progress {
let store = shrink_in_progress.old_storage().clone();
not_retaining_store(&store);
// shrink is in progress, so 1 new append vec to keep, 1 old one to throw away
let store = shrink_in_progress.old_storage();
not_retaining_store(store);
// drop removes the old append vec that was being shrunk from db's storage
drop(shrink_in_progress);
slot_stores.read().unwrap().len()
} else {
// no shrink_in_progress, so retain append vecs depending on 'should_retain'
let mut list = slot_stores.write().unwrap();
list.retain(|_key, store| {
if !should_retain(store) {
Expand Down Expand Up @@ -4581,7 +4584,7 @@ impl AccountsDb {
self.accounts_index
.clean_dead_slot(*slot, &mut AccountsIndexRootsStats::default());
self.bank_hashes.write().unwrap().remove(slot);
// all storages have been removed from here and recycled or dropped
// all storages have been removed from this slot and recycled or dropped
assert!(self
.storage
.remove(slot)
Expand Down Expand Up @@ -16495,6 +16498,19 @@ pub mod tests {
);
}

#[test]
fn test_mark_dirty_dead_stores_empty() {
let db = AccountsDb::new_single_for_tests();
let slot = 0;
for add_dirty_stores in [false, true] {
let (remaining_stores, dead_storages) =
db.mark_dirty_dead_stores(slot, |_| true, add_dirty_stores, None);
assert_eq!(remaining_stores, 0);
assert!(dead_storages.is_empty());
assert!(db.dirty_stores.is_empty());
}
}

#[test]
fn test_mark_dirty_dead_stores() {
let db = AccountsDb::new_single_for_tests();
Expand Down

0 comments on commit 38d771a

Please sign in to comment.