From 8d0016d7fd093bab5307c47da2572e570debd59d Mon Sep 17 00:00:00 2001 From: jeff washington Date: Tue, 3 Jan 2023 09:27:26 -0600 Subject: [PATCH] should_move_to_ancient_append_vec works with a single storage --- runtime/src/accounts_db.rs | 58 ++++++++++++++------------------------ 1 file changed, 21 insertions(+), 37 deletions(-) diff --git a/runtime/src/accounts_db.rs b/runtime/src/accounts_db.rs index 240ba1cf6dae16..d43f224fac605e 100644 --- a/runtime/src/accounts_db.rs +++ b/runtime/src/accounts_db.rs @@ -4264,6 +4264,7 @@ impl AccountsDb { .unwrap_or_default() } + #[cfg(test)] fn get_storages_for_slot(&self, slot: Slot) -> Option { self.storage.get_slot_storage_entries(slot) } @@ -4316,15 +4317,17 @@ impl AccountsDb { current_ancient: &mut CurrentAncientAppendVec, can_randomly_shrink: bool, ) -> Option { - self.get_storages_for_slot(slot).and_then(|all_storages| { - self.should_move_to_ancient_append_vec( - &all_storages, - current_ancient, - slot, - can_randomly_shrink, - ) - .then_some(all_storages) - }) + self.storage + .get_slot_storage_entry(slot) + .and_then(|storage| { + self.should_move_to_ancient_append_vec( + &storage, + current_ancient, + slot, + can_randomly_shrink, + ) + .then_some(vec![storage]) + }) } /// return true if the accounts in this slot should be moved to an ancient append vec @@ -4335,19 +4338,11 @@ impl AccountsDb { /// this is not useful for testing fn should_move_to_ancient_append_vec( &self, - all_storages: &SnapshotStorage, + storage: &Arc, current_ancient: &mut CurrentAncientAppendVec, slot: Slot, can_randomly_shrink: bool, ) -> bool { - if all_storages.len() != 1 { - // we are dealing with roots that are more than 1 epoch old. I chose not to support or test the case where we have > 1 append vec per slot. - // So, such slots will NOT participate in ancient shrinking. - // since we skipped an ancient append vec, we don't want to append to whatever append vec USED to be the current one - *current_ancient = CurrentAncientAppendVec::default(); - return false; - } - let storage = all_storages.first().unwrap(); let accounts = &storage.accounts; self.shrink_ancient_stats @@ -17842,7 +17837,7 @@ pub mod tests { let mut current_ancient = CurrentAncientAppendVec::default(); let should_move = db.should_move_to_ancient_append_vec( - &storages, + &storages[0], &mut current_ancient, slot5, CAN_RANDOMLY_SHRINK_FALSE, @@ -17850,21 +17845,10 @@ pub mod tests { assert!(current_ancient.slot_and_append_vec.is_none()); // slot is not ancient, so it is good to move assert!(should_move); - // try 2 storages in 1 slot, should not be able to move - current_ancient = CurrentAncientAppendVec::new(slot5, Arc::clone(&storages[0])); // just 'some', contents don't matter - let two_storages = vec![storages[0].clone(), storages[0].clone()]; - let should_move = db.should_move_to_ancient_append_vec( - &two_storages, - &mut current_ancient, - slot5, - CAN_RANDOMLY_SHRINK_FALSE, - ); - assert!(current_ancient.slot_and_append_vec.is_none()); - assert!(!should_move); current_ancient = CurrentAncientAppendVec::new(slot5, Arc::clone(&storages[0])); // just 'some', contents don't matter let should_move = db.should_move_to_ancient_append_vec( - &storages, + &storages[0], &mut current_ancient, slot5, CAN_RANDOMLY_SHRINK_FALSE, @@ -17884,7 +17868,7 @@ pub mod tests { let _existing_append_vec = db.create_and_insert_store(slot1_ancient, 1000, "test"); let ancient1 = db.create_ancient_append_vec(slot1_ancient); let should_move = db.should_move_to_ancient_append_vec( - &vec![ancient1.new_storage().clone()], + &ancient1.new_storage().clone(), &mut current_ancient, slot1_ancient, CAN_RANDOMLY_SHRINK_FALSE, @@ -17906,7 +17890,7 @@ pub mod tests { let _existing_append_vec = db.create_and_insert_store(slot2_ancient, 1000, "test"); let ancient2 = db.create_ancient_append_vec(slot2_ancient); let should_move = db.should_move_to_ancient_append_vec( - &vec![ancient2.new_storage().clone()], + &ancient2.new_storage().clone(), &mut current_ancient, slot2_ancient, CAN_RANDOMLY_SHRINK_FALSE, @@ -17926,7 +17910,7 @@ pub mod tests { let _existing_append_vec = db.create_and_insert_store(slot3_full_ancient, 1000, "test"); let full_ancient_3 = make_full_ancient_append_vec(&db, slot3_full_ancient); let should_move = db.should_move_to_ancient_append_vec( - &vec![full_ancient_3.new_storage().clone()], + &full_ancient_3.new_storage().clone(), &mut current_ancient, slot3_full_ancient, CAN_RANDOMLY_SHRINK_FALSE, @@ -17942,7 +17926,7 @@ pub mod tests { let mut current_ancient = CurrentAncientAppendVec::new(slot1_ancient, ancient1.new_storage().clone()); let should_move = db.should_move_to_ancient_append_vec( - &vec![full_ancient_3.new_storage().clone()], + &full_ancient_3.new_storage().clone(), &mut current_ancient, slot3_full_ancient, CAN_RANDOMLY_SHRINK_FALSE, @@ -17960,7 +17944,7 @@ pub mod tests { // should shrink here, returning none for current let mut current_ancient = CurrentAncientAppendVec::default(); let should_move = db.should_move_to_ancient_append_vec( - &vec![full_ancient_3.new_storage().clone()], + &full_ancient_3.new_storage().clone(), &mut current_ancient, slot3_full_ancient, CAN_RANDOMLY_SHRINK_FALSE, @@ -17973,7 +17957,7 @@ pub mod tests { let mut current_ancient = CurrentAncientAppendVec::new(slot1_ancient, ancient1.new_storage().clone()); let should_move = db.should_move_to_ancient_append_vec( - &vec![Arc::clone(full_ancient_3.new_storage())], + &Arc::clone(full_ancient_3.new_storage()), &mut current_ancient, slot3_full_ancient, CAN_RANDOMLY_SHRINK_FALSE,