Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4396,11 +4396,9 @@ impl AccountsDb {

/// return all slots that are more than one epoch old and thus could already be an ancient append vec
/// or which could need to be combined into a new or existing ancient append vec
/// offset is used to combine newer slots than we normally would. This is designed to be used for testing.
fn get_sorted_potential_ancient_slots(&self, oldest_non_ancient_slot: Slot) -> Vec<Slot> {
let mut ancient_slots = self.get_roots_less_than(oldest_non_ancient_slot);
ancient_slots.sort_unstable();
ancient_slots
/// offset is used to combine newer slots than we normally would.
fn get_potential_ancient_slots(&self, oldest_non_ancient_slot: Slot) -> Vec<Slot> {
self.get_roots_less_than(oldest_non_ancient_slot)
}

/// get a sorted list of slots older than an epoch
Expand All @@ -4412,11 +4410,13 @@ impl AccountsDb {

let oldest_non_ancient_slot = self.get_oldest_non_ancient_slot(epoch_schedule);
let can_randomly_shrink = true;
let sorted_slots = self.get_sorted_potential_ancient_slots(oldest_non_ancient_slot);
let mut ancient_slots = self.get_potential_ancient_slots(oldest_non_ancient_slot);
if self.create_ancient_storage == CreateAncientStorage::Append {
self.combine_ancient_slots(sorted_slots, can_randomly_shrink);
// 'Append' require that 'ancient_slots' to be sorted.
ancient_slots.sort_unstable();
self.combine_ancient_slots(ancient_slots, can_randomly_shrink);
} else {
self.combine_ancient_slots_packed(sorted_slots, can_randomly_shrink);
self.combine_ancient_slots_packed(ancient_slots, can_randomly_shrink);
}
}

Expand Down Expand Up @@ -9774,6 +9774,12 @@ pub mod tests {
fn get_storage_for_slot(&self, slot: Slot) -> Option<Arc<AccountStorageEntry>> {
self.storage.get_slot_storage_entry(slot)
}

fn get_sorted_potential_ancient_slots(&self, oldest_non_ancient_slot: Slot) -> Vec<Slot> {
Copy link
Copy Markdown
Author

@HaoranYi HaoranYi Jun 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the original get_sorted_potential_ancient_slots to test-only context to keep test happy 😄

let mut ancient_slots = self.get_potential_ancient_slots(oldest_non_ancient_slot);
ancient_slots.sort_unstable();
ancient_slots
}
}

/// this tuple contains slot info PER account
Expand Down
26 changes: 11 additions & 15 deletions accounts-db/src/ancient_append_vecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,17 @@ impl AncientSlotInfos {
self.filter_by_smallest_capacity(tuning);
}

// sort 'shrink_indexes' by most bytes saved, highest to lowest
// sort 'shrink_indexes' by most bytes saved descending (i.e. highest to lowest)
// then sort by slots ascending.
fn sort_shrink_indexes_by_bytes_saved(&mut self) {
self.shrink_indexes.sort_unstable_by(|l, r| {
let amount_shrunk = |index: &usize| {
let item = &self.all_infos[*index];
item.capacity - item.alive_bytes
};
amount_shrunk(r).cmp(&amount_shrunk(l))
amount_shrunk(r)
.cmp(&amount_shrunk(l))
.then(self.all_infos[*l].slot.cmp(&self.all_infos[*r].slot))
});
}

Expand Down Expand Up @@ -267,11 +270,7 @@ impl AccountsDb {
/// After this function the number of alive roots is <= # alive roots when it was called.
/// In practice, the # of alive roots after will be significantly less than # alive roots when called.
/// Trying to reduce # roots and storages (one per root) required to store all the data in ancient slots
pub(crate) fn combine_ancient_slots_packed(
&self,
sorted_slots: Vec<Slot>,
can_randomly_shrink: bool,
) {
pub(crate) fn combine_ancient_slots_packed(&self, slots: Vec<Slot>, can_randomly_shrink: bool) {
let tuning = PackedAncientStorageTuning {
// only allow 10k slots old enough to be ancient
max_ancient_slots: 10_000,
Expand All @@ -286,11 +285,8 @@ impl AccountsDb {

let mut stats_sub = ShrinkStatsSub::default();

let (_, total_us) = measure_us!(self.combine_ancient_slots_packed_internal(
sorted_slots,
tuning,
&mut stats_sub
));
let (_, total_us) =
measure_us!(self.combine_ancient_slots_packed_internal(slots, tuning, &mut stats_sub));

Self::update_shrink_stats(&self.shrink_ancient_stats.shrink_stats, stats_sub, false);
self.shrink_ancient_stats
Expand Down Expand Up @@ -333,14 +329,14 @@ impl AccountsDb {

fn combine_ancient_slots_packed_internal(
&self,
sorted_slots: Vec<Slot>,
slots: Vec<Slot>,
tuning: PackedAncientStorageTuning,
metrics: &mut ShrinkStatsSub,
) {
self.shrink_ancient_stats
.slots_considered
.fetch_add(sorted_slots.len() as u64, Ordering::Relaxed);
let ancient_slot_infos = self.collect_sort_filter_ancient_slots(sorted_slots, &tuning);
.fetch_add(slots.len() as u64, Ordering::Relaxed);
let ancient_slot_infos = self.collect_sort_filter_ancient_slots(slots, &tuning);

if ancient_slot_infos.all_infos.is_empty() {
return; // nothing to do
Expand Down