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

Commit 61caae6

Browse files
v1.17: ancient shrink on its own cadence (backport of #33712) (#34060)
ancient shrink on its own cadence (#33712) (cherry picked from commit d948e5b) Co-authored-by: Jeff Washington (jwash) <[email protected]>
1 parent 0a195ad commit 61caae6

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

accounts-db/src/accounts_db.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -4395,11 +4395,12 @@ impl AccountsDb {
43954395

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

4403+
let oldest_non_ancient_slot = self.get_oldest_non_ancient_slot(epoch_schedule);
44034404
let can_randomly_shrink = true;
44044405
let sorted_slots = self.get_sorted_potential_ancient_slots(oldest_non_ancient_slot);
44054406
if self.create_ancient_storage == CreateAncientStorage::Append {
@@ -4744,10 +4745,6 @@ impl AccountsDb {
47444745

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

47524749
let shrink_candidates_slots =
47534750
std::mem::take(&mut *self.shrink_candidate_slots.lock().unwrap());

runtime/src/accounts_background_service.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use {
2121
solana_accounts_db::{
2222
accounts_db::CalcAccountsHashDataSource, accounts_hash::CalcAccountsHashConfig,
2323
},
24-
solana_measure::measure::Measure,
24+
solana_measure::{measure::Measure, measure_us},
2525
solana_sdk::clock::{BankId, Slot},
2626
stats::StatsManager,
2727
std::{
@@ -383,6 +383,8 @@ impl SnapshotRequestHandler {
383383
snapshot_root_bank.clean_accounts(*last_full_snapshot_slot);
384384
clean_time.stop();
385385

386+
let (_, shrink_ancient_time_us) = measure_us!(snapshot_root_bank.shrink_ancient_slots());
387+
386388
let mut shrink_time = Measure::start("shrink_time");
387389
snapshot_root_bank.shrink_candidate_slots();
388390
shrink_time.stop();
@@ -464,6 +466,7 @@ impl SnapshotRequestHandler {
464466
("snapshot_time", snapshot_time.as_us(), i64),
465467
("total_us", total_time.as_us(), i64),
466468
("non_snapshot_time_us", non_snapshot_time_us, i64),
469+
("shrink_ancient_time_us", shrink_ancient_time_us, i64),
467470
);
468471
Ok(snapshot_root_bank.block_height())
469472
}
@@ -705,6 +708,7 @@ impl AccountsBackgroundService {
705708
bank.force_flush_accounts_cache();
706709
bank.clean_accounts(last_full_snapshot_slot);
707710
last_cleaned_block_height = bank.block_height();
711+
bank.shrink_ancient_slots();
708712
}
709713
bank.shrink_candidate_slots();
710714
}

runtime/src/bank.rs

+7
Original file line numberDiff line numberDiff line change
@@ -7817,6 +7817,13 @@ impl Bank {
78177817
.shrink_candidate_slots(self.epoch_schedule())
78187818
}
78197819

7820+
pub(crate) fn shrink_ancient_slots(&self) {
7821+
self.rc
7822+
.accounts
7823+
.accounts_db
7824+
.shrink_ancient_slots(self.epoch_schedule())
7825+
}
7826+
78207827
pub fn no_overflow_rent_distribution_enabled(&self) -> bool {
78217828
self.feature_set
78227829
.is_active(&feature_set::no_overflow_rent_distribution::id())

0 commit comments

Comments
 (0)