handle_dropped_roots_for_ancient takes iter (#30190)

This commit is contained in:
Jeff Washington (jwash) 2023-02-08 11:40:49 -06:00 committed by GitHub
parent 0da4697b2f
commit 427bd62642
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 16 deletions

View File

@ -4487,7 +4487,7 @@ impl AccountsDb {
);
}
self.handle_dropped_roots_for_ancient(dropped_roots);
self.handle_dropped_roots_for_ancient(dropped_roots.into_iter());
total.stop();
self.shrink_ancient_stats
@ -4601,16 +4601,17 @@ impl AccountsDb {
/// each slot in 'dropped_roots' has been combined into an ancient append vec.
/// We are done with the slot now forever.
pub(crate) fn handle_dropped_roots_for_ancient(&self, dropped_roots: Vec<Slot>) {
if !dropped_roots.is_empty() {
dropped_roots.iter().for_each(|slot| {
self.accounts_index
.clean_dead_slot(*slot, &mut AccountsIndexRootsStats::default());
self.remove_bank_hash_info(slot);
// the storage has been removed from this slot and recycled or dropped
assert!(self.storage.remove(slot).is_none());
});
}
pub(crate) fn handle_dropped_roots_for_ancient(
&self,
dropped_roots: impl Iterator<Item = Slot>,
) {
dropped_roots.for_each(|slot| {
self.accounts_index
.clean_dead_slot(slot, &mut AccountsIndexRootsStats::default());
self.remove_bank_hash_info(&slot);
// the storage has been removed from this slot and recycled or dropped
assert!(self.storage.remove(&slot).is_none());
});
}
/// add all 'pubkeys' into the set of pubkeys that are 'uncleaned', associated with 'slot'
@ -17432,7 +17433,7 @@ pub mod tests {
assert!(db.storage.is_empty_entry(next_slot));
// this removes the storages entry completely from the hashmap for 'next_slot'.
// Otherwise, we have a zero length vec in that hashmap
db.handle_dropped_roots_for_ancient(dropped_roots);
db.handle_dropped_roots_for_ancient(dropped_roots.into_iter());
assert!(db.storage.get_slot_storage_entry(next_slot).is_none());
// include all the slots we put into the ancient append vec - they should contain nothing
@ -17682,7 +17683,7 @@ pub mod tests {
fn test_handle_dropped_roots_for_ancient() {
solana_logger::setup();
let db = AccountsDb::new_single_for_tests();
db.handle_dropped_roots_for_ancient(Vec::default());
db.handle_dropped_roots_for_ancient(std::iter::empty::<Slot>());
let slot0 = 0;
let dropped_roots = vec![slot0];
assert!(db.get_bank_hash_stats(slot0).is_some());
@ -17690,7 +17691,7 @@ pub mod tests {
db.accounts_index.add_uncleaned_roots([slot0].into_iter());
assert!(db.accounts_index.is_uncleaned_root(slot0));
assert!(db.accounts_index.is_alive_root(slot0));
db.handle_dropped_roots_for_ancient(dropped_roots);
db.handle_dropped_roots_for_ancient(dropped_roots.into_iter());
assert!(db.get_bank_hash_stats(slot0).is_none());
assert!(!db.accounts_index.is_uncleaned_root(slot0));
assert!(!db.accounts_index.is_alive_root(slot0));
@ -17701,7 +17702,7 @@ pub mod tests {
}
#[test]
#[should_panic(expected = "assertion failed: self.storage.remove(slot).is_none()")]
#[should_panic(expected = "assertion failed: self.storage.remove")]
fn test_handle_dropped_roots_for_ancient_assert() {
solana_logger::setup();
let common_store_path = Path::new("");
@ -17716,7 +17717,7 @@ pub mod tests {
let slot0 = 0;
let dropped_roots = vec![slot0];
insert_store(&db, entry);
db.handle_dropped_roots_for_ancient(dropped_roots);
db.handle_dropped_roots_for_ancient(dropped_roots.into_iter());
}
#[test]