From 1882362aac22278e91984763cbeb752dd83c2cc4 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Mon, 16 Oct 2023 10:06:20 -0700 Subject: [PATCH] ancient shrink on its own cadence (#33712) (cherry picked from commit d948e5bf69a0b8093b5e509273d6bb9ecb5acbaf) --- 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 dad1f152f36de2..9750ebd78d09d8 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -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 { @@ -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()); 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 c0170ae113f94e..35ea77e8b555c0 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -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())