ancient append vecs: pass through can_randomly_shrink (#28706)

This commit is contained in:
Jeff Washington (jwash) 2022-11-01 11:55:28 -07:00 committed by GitHub
parent 9ff9051d87
commit 7885fdca37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 53 additions and 24 deletions

View File

@ -4287,7 +4287,11 @@ impl AccountsDb {
return; return;
} }
self.combine_ancient_slots(self.get_sorted_potential_ancient_slots()); let can_randomly_shrink = true;
self.combine_ancient_slots(
self.get_sorted_potential_ancient_slots(),
can_randomly_shrink,
);
} }
/// create and return new ancient append vec /// create and return new ancient append vec
@ -4362,8 +4366,8 @@ impl AccountsDb {
&self, &self,
slot: Slot, slot: Slot,
current_ancient: &mut CurrentAncientAppendVec, current_ancient: &mut CurrentAncientAppendVec,
can_randomly_shrink: bool,
) -> Option<SnapshotStorage> { ) -> Option<SnapshotStorage> {
let can_randomly_shrink = true;
self.get_storages_for_slot(slot).and_then(|all_storages| { self.get_storages_for_slot(slot).and_then(|all_storages| {
self.should_move_to_ancient_append_vec( self.should_move_to_ancient_append_vec(
&all_storages, &all_storages,
@ -4424,8 +4428,8 @@ impl AccountsDb {
} }
/// Combine all account data from storages in 'sorted_slots' into ancient append vecs. /// Combine all account data from storages in 'sorted_slots' into ancient append vecs.
/// This keeps us from accumulating append vecs in slots older than an epoch. /// This keeps us from accumulating append vecs for each slot older than an epoch.
fn combine_ancient_slots(&self, sorted_slots: Vec<Slot>) { fn combine_ancient_slots(&self, sorted_slots: Vec<Slot>, can_randomly_shrink: bool) {
if sorted_slots.is_empty() { if sorted_slots.is_empty() {
return; return;
} }
@ -4440,8 +4444,11 @@ impl AccountsDb {
let len = sorted_slots.len(); let len = sorted_slots.len();
for slot in sorted_slots { for slot in sorted_slots {
let old_storages = let old_storages = match self.get_storages_to_move_to_ancient_append_vec(
match self.get_storages_to_move_to_ancient_append_vec(slot, &mut current_ancient) { slot,
&mut current_ancient,
can_randomly_shrink,
) {
Some(old_storages) => old_storages, Some(old_storages) => old_storages,
None => { None => {
// nothing to squash for this slot // nothing to squash for this slot
@ -17567,6 +17574,16 @@ pub mod tests {
} }
} }
const CAN_RANDOMLY_SHRINK_FALSE: bool = false;
#[test]
fn test_combine_ancient_slots_empty() {
solana_logger::setup();
let db = AccountsDb::new_single_for_tests();
// empty slots
db.combine_ancient_slots(Vec::default(), CAN_RANDOMLY_SHRINK_FALSE);
}
#[test] #[test]
fn test_handle_dropped_roots_for_ancient() { fn test_handle_dropped_roots_for_ancient() {
solana_logger::setup(); solana_logger::setup();
@ -17631,8 +17648,12 @@ pub mod tests {
.unwrap(); .unwrap();
let mut current_ancient = CurrentAncientAppendVec::default(); let mut current_ancient = CurrentAncientAppendVec::default();
let should_move = let should_move = db.should_move_to_ancient_append_vec(
db.should_move_to_ancient_append_vec(&storages, &mut current_ancient, slot5, false); &storages,
&mut current_ancient,
slot5,
CAN_RANDOMLY_SHRINK_FALSE,
);
assert!(current_ancient.is_none()); assert!(current_ancient.is_none());
// slot is not ancient, so it is good to move // slot is not ancient, so it is good to move
assert!(should_move); assert!(should_move);
@ -17640,14 +17661,22 @@ pub mod tests {
// try 2 storages in 1 slot, should not be able to 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 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 two_storages = vec![storages[0].clone(), storages[0].clone()];
let should_move = let should_move = db.should_move_to_ancient_append_vec(
db.should_move_to_ancient_append_vec(&two_storages, &mut current_ancient, slot5, false); &two_storages,
&mut current_ancient,
slot5,
CAN_RANDOMLY_SHRINK_FALSE,
);
assert!(current_ancient.is_none()); assert!(current_ancient.is_none());
assert!(!should_move); assert!(!should_move);
current_ancient = CurrentAncientAppendVec::new(slot5, Arc::clone(&storages[0])); // just 'some', contents don't matter current_ancient = CurrentAncientAppendVec::new(slot5, Arc::clone(&storages[0])); // just 'some', contents don't matter
let should_move = let should_move = db.should_move_to_ancient_append_vec(
db.should_move_to_ancient_append_vec(&storages, &mut current_ancient, slot5, false); &storages,
&mut current_ancient,
slot5,
CAN_RANDOMLY_SHRINK_FALSE,
);
// should have kept the same 'current_ancient' // should have kept the same 'current_ancient'
assert_eq!(current_ancient.slot(), slot5); assert_eq!(current_ancient.slot(), slot5);
assert_eq!(current_ancient.append_vec().slot(), slot5); assert_eq!(current_ancient.append_vec().slot(), slot5);
@ -17664,7 +17693,7 @@ pub mod tests {
&vec![ancient1.clone()], &vec![ancient1.clone()],
&mut current_ancient, &mut current_ancient,
slot1_ancient, slot1_ancient,
false, CAN_RANDOMLY_SHRINK_FALSE,
); );
assert!(!should_move); assert!(!should_move);
assert_eq!(current_ancient.append_vec_id(), ancient1.append_vec_id()); assert_eq!(current_ancient.append_vec_id(), ancient1.append_vec_id());
@ -17680,7 +17709,7 @@ pub mod tests {
&vec![ancient2.clone()], &vec![ancient2.clone()],
&mut current_ancient, &mut current_ancient,
slot2_ancient, slot2_ancient,
false, CAN_RANDOMLY_SHRINK_FALSE,
); );
assert!(!should_move); assert!(!should_move);
assert_eq!(current_ancient.append_vec_id(), ancient2.append_vec_id()); assert_eq!(current_ancient.append_vec_id(), ancient2.append_vec_id());
@ -17695,7 +17724,7 @@ pub mod tests {
&vec![full_ancient_3.clone()], &vec![full_ancient_3.clone()],
&mut current_ancient, &mut current_ancient,
slot3_full_ancient, slot3_full_ancient,
false, CAN_RANDOMLY_SHRINK_FALSE,
); );
assert!(!should_move); assert!(!should_move);
assert_eq!( assert_eq!(
@ -17710,7 +17739,7 @@ pub mod tests {
&vec![full_ancient_3.clone()], &vec![full_ancient_3.clone()],
&mut current_ancient, &mut current_ancient,
slot3_full_ancient, slot3_full_ancient,
false, CAN_RANDOMLY_SHRINK_FALSE,
); );
assert!(!should_move); assert!(!should_move);
assert_eq!( assert_eq!(
@ -17728,7 +17757,7 @@ pub mod tests {
&vec![full_ancient_3.clone()], &vec![full_ancient_3.clone()],
&mut current_ancient, &mut current_ancient,
slot3_full_ancient, slot3_full_ancient,
false, CAN_RANDOMLY_SHRINK_FALSE,
); );
assert!(should_move); assert!(should_move);
assert!(current_ancient.is_none()); assert!(current_ancient.is_none());
@ -17740,7 +17769,7 @@ pub mod tests {
&vec![full_ancient_3], &vec![full_ancient_3],
&mut current_ancient, &mut current_ancient,
slot3_full_ancient, slot3_full_ancient,
false, CAN_RANDOMLY_SHRINK_FALSE,
); );
assert!(should_move); assert!(should_move);
assert_eq!(current_ancient.append_vec_id(), ancient1.append_vec_id()); assert_eq!(current_ancient.append_vec_id(), ancient1.append_vec_id());