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

Commit 05c54b5

Browse files
ancient shrink on its own cadence
1 parent 167dac2 commit 05c54b5

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

accounts-db/src/accounts_db.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4403,11 +4403,12 @@ impl AccountsDb {
44034403

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

4411+
let oldest_non_ancient_slot = self.get_oldest_non_ancient_slot(epoch_schedule);
44114412
let can_randomly_shrink = true;
44124413
let sorted_slots = self.get_sorted_potential_ancient_slots(oldest_non_ancient_slot);
44134414
if self.create_ancient_storage == CreateAncientStorage::Append {
@@ -4752,10 +4753,6 @@ impl AccountsDb {
47524753

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

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

runtime/src/accounts_background_service.rs

Lines changed: 5 additions & 1 deletion
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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7952,6 +7952,13 @@ impl Bank {
79527952
.shrink_candidate_slots(self.epoch_schedule())
79537953
}
79547954

7955+
pub(crate) fn shrink_ancient_slots(&self) {
7956+
self.rc
7957+
.accounts
7958+
.accounts_db
7959+
.shrink_ancient_slots(self.epoch_schedule())
7960+
}
7961+
79557962
pub fn no_overflow_rent_distribution_enabled(&self) -> bool {
79567963
self.feature_set
79577964
.is_active(&feature_set::no_overflow_rent_distribution::id())

0 commit comments

Comments
 (0)