Skip to content

Commit

Permalink
v1.17: ancient shrink on its own cadence (backport of #33712) (#34060)
Browse files Browse the repository at this point in the history
ancient shrink on its own cadence (#33712)

(cherry picked from commit d948e5b)

Co-authored-by: Jeff Washington (jwash) <jeff.washington@solana.com>
  • Loading branch information
mergify[bot] and jeffwashington authored Nov 17, 2023
1 parent 0a195ad commit 61caae6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
7 changes: 2 additions & 5 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4395,11 +4395,12 @@ impl AccountsDb {

/// get a sorted list of slots older than an epoch
/// squash those slots into ancient append vecs
fn shrink_ancient_slots(&self, oldest_non_ancient_slot: Slot) {
pub fn shrink_ancient_slots(&self, epoch_schedule: &EpochSchedule) {
if self.ancient_append_vec_offset.is_none() {
return;
}

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);
if self.create_ancient_storage == CreateAncientStorage::Append {
Expand Down Expand Up @@ -4744,10 +4745,6 @@ impl AccountsDb {

pub fn shrink_candidate_slots(&self, epoch_schedule: &EpochSchedule) -> usize {
let oldest_non_ancient_slot = self.get_oldest_non_ancient_slot(epoch_schedule);
if !self.shrink_candidate_slots.lock().unwrap().is_empty() {
// this can affect 'shrink_candidate_slots', so don't 'take' it until after this completes
self.shrink_ancient_slots(oldest_non_ancient_slot);
}

let shrink_candidates_slots =
std::mem::take(&mut *self.shrink_candidate_slots.lock().unwrap());
Expand Down
6 changes: 5 additions & 1 deletion runtime/src/accounts_background_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use {
solana_accounts_db::{
accounts_db::CalcAccountsHashDataSource, accounts_hash::CalcAccountsHashConfig,
},
solana_measure::measure::Measure,
solana_measure::{measure::Measure, measure_us},
solana_sdk::clock::{BankId, Slot},
stats::StatsManager,
std::{
Expand Down Expand Up @@ -383,6 +383,8 @@ impl SnapshotRequestHandler {
snapshot_root_bank.clean_accounts(*last_full_snapshot_slot);
clean_time.stop();

let (_, shrink_ancient_time_us) = measure_us!(snapshot_root_bank.shrink_ancient_slots());

let mut shrink_time = Measure::start("shrink_time");
snapshot_root_bank.shrink_candidate_slots();
shrink_time.stop();
Expand Down Expand Up @@ -464,6 +466,7 @@ impl SnapshotRequestHandler {
("snapshot_time", snapshot_time.as_us(), i64),
("total_us", total_time.as_us(), i64),
("non_snapshot_time_us", non_snapshot_time_us, i64),
("shrink_ancient_time_us", shrink_ancient_time_us, i64),
);
Ok(snapshot_root_bank.block_height())
}
Expand Down Expand Up @@ -705,6 +708,7 @@ impl AccountsBackgroundService {
bank.force_flush_accounts_cache();
bank.clean_accounts(last_full_snapshot_slot);
last_cleaned_block_height = bank.block_height();
bank.shrink_ancient_slots();
}
bank.shrink_candidate_slots();
}
Expand Down
7 changes: 7 additions & 0 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7817,6 +7817,13 @@ impl Bank {
.shrink_candidate_slots(self.epoch_schedule())
}

pub(crate) fn shrink_ancient_slots(&self) {
self.rc
.accounts
.accounts_db
.shrink_ancient_slots(self.epoch_schedule())
}

pub fn no_overflow_rent_distribution_enabled(&self) -> bool {
self.feature_set
.is_active(&feature_set::no_overflow_rent_distribution::id())
Expand Down

0 comments on commit 61caae6

Please sign in to comment.