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

Commit

Permalink
ancient pack: add low water mark
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington committed Oct 20, 2023
1 parent 6fd0dcb commit fb35ac2
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions accounts-db/src/ancient_append_vecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,17 @@ impl AncientSlotInfos {
self.shrink_indexes.clear();
let total_storages = self.all_infos.len();
let mut cumulative_bytes = 0u64;
let low_threshold = max_storages * 50 / 100;
for (i, info) in self.all_infos.iter().enumerate() {
saturating_add_assign!(cumulative_bytes, info.alive_bytes);
let ancient_storages_required = (cumulative_bytes / ideal_storage_size + 1) as usize;
let storages_remaining = total_storages - i - 1;

// if the remaining uncombined storages and the # of resulting
// combined ancient storages is less than the threshold, then
// we've gone too far, so get rid of this entry and all after it.
// Every storage after this one is larger.
if storages_remaining + ancient_storages_required < max_storages {
if storages_remaining + ancient_storages_required < low_threshold {
self.all_infos.truncate(i);
break;
}
Expand Down Expand Up @@ -2468,7 +2470,20 @@ pub mod tests {
max_storages,
NonZeroU64::new(ideal_storage_size_large).unwrap(),
);
assert!(infos.all_infos.is_empty());

if filter {
assert!(infos.all_infos.is_empty());
} else {
// no short circuit, so truncate to shrink below low water
assert_eq!(
infos
.all_infos
.iter()
.map(|info| info.slot)
.collect::<Vec<_>>(),
vec![0]
);
}

let mut infos = create_test_infos(1);
infos.all_infos[0].alive_bytes = ideal_storage_size_large + 1;
Expand Down Expand Up @@ -2501,14 +2516,14 @@ pub mod tests {
assert_eq!(infos.all_infos.len(), 2);
}

// max is 3
// 4 storages
// storage[3] is big enough to cause us to need another storage
// so, storage[0] and [1] can be combined into 1, resulting in 3 remaining storages, which is
// the goal, so we only have to combine the first 2 to hit the goal
let mut infos = create_test_infos(4);
infos.all_infos[3].alive_bytes = ideal_storage_size_large;
let max_storages = 3;
// max is 4
// 5 storages
// storage[4] is big enough to cause us to need another storage
// so, storage[0..=2] can be combined into 1, resulting in 3 remaining storages, which is
// the goal, so we only have to combine the first 3 to hit the goal
let mut infos = create_test_infos(5);
infos.all_infos[4].alive_bytes = ideal_storage_size_large;
let max_storages = 4;
test(
&mut infos,
max_storages,
Expand All @@ -2520,7 +2535,7 @@ pub mod tests {
.iter()
.map(|info| info.slot)
.collect::<Vec<_>>(),
vec![0, 1]
vec![0, 1, 2, 3, 4]
);
}
}
Expand Down

0 comments on commit fb35ac2

Please sign in to comment.