From 05c54b57d7743d363a4529b0fac852b4c9df2b91 Mon Sep 17 00:00:00 2001 From: jeff washington Date: Mon, 16 Oct 2023 09:45:42 -0500 Subject: [PATCH] ancient shrink on its own cadence --- accounts-db/src/accounts_db.rs | 7 ++----- runtime/src/accounts_background_service.rs | 6 +++++- runtime/src/bank.rs | 7 +++++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index b4162eeecabaa3..6ccd88349d533d 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -4403,11 +4403,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 { @@ -4752,10 +4753,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()); diff --git a/runtime/src/accounts_background_service.rs b/runtime/src/accounts_background_service.rs index 627ccbf76adaa5..b826f8eddc5724 100644 --- a/runtime/src/accounts_background_service.rs +++ b/runtime/src/accounts_background_service.rs @@ -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::{ @@ -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(); @@ -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()) } @@ -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(); } diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 5227db287c9f10..1eb555358151fd 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -7952,6 +7952,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())