From fa9205e75fdb7279ee516f93ccd398d6ff7e9197 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Tue, 30 Jul 2024 09:57:22 -0500 Subject: [PATCH] clean doesn't try to remove older entries on 1 elem slot list (#2308) * clean doesn't try to remove older entries on 1 elem slot list * move useless --- accounts-db/src/accounts_db.rs | 26 ++++++++++++++++++++++++-- accounts-db/src/accounts_index.rs | 7 +++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index c06fb5408466be..94834338c18ee0 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -1937,6 +1937,7 @@ struct CleanAccountsStats { remove_dead_accounts_remove_us: AtomicU64, remove_dead_accounts_shrink_us: AtomicU64, clean_stored_dead_slots_us: AtomicU64, + uncleaned_roots_slot_list_1: AtomicU64, } impl CleanAccountsStats { @@ -3282,8 +3283,15 @@ impl AccountsDb { { assert!(slot <= &max_clean_root_inclusive); } - purges_old_accounts.push(*candidate); - useless = false; + if slot_list.len() > 1 { + // no need to purge old accounts if there is only 1 slot in the slot list + purges_old_accounts.push(*candidate); + useless = false; + } else { + self.clean_accounts_stats + .uncleaned_roots_slot_list_1 + .fetch_add(1, Ordering::Relaxed); + } } } None => { @@ -3497,6 +3505,13 @@ impl AccountsDb { ), ("scan_missing", missing_accum.load(Ordering::Relaxed), i64), ("uncleaned_roots_len", uncleaned_roots.len(), i64), + ( + "uncleaned_roots_slot_list_1", + self.clean_accounts_stats + .uncleaned_roots_slot_list_1 + .swap(0, Ordering::Relaxed), + i64 + ), ( "clean_old_root_us", self.clean_accounts_stats @@ -3544,6 +3559,13 @@ impl AccountsDb { self.accounts_index.roots_added.swap(0, Ordering::Relaxed), i64 ), + ( + "purge_older_root_entries_one_slot_list", + self.accounts_index + .purge_older_root_entries_one_slot_list + .swap(0, Ordering::Relaxed), + i64 + ), ( "roots_removed", self.accounts_index.roots_removed.swap(0, Ordering::Relaxed), diff --git a/accounts-db/src/accounts_index.rs b/accounts-db/src/accounts_index.rs index ee0392ce856873..dc10df29d67e35 100644 --- a/accounts-db/src/accounts_index.rs +++ b/accounts-db/src/accounts_index.rs @@ -666,6 +666,8 @@ pub struct AccountsIndex + Into> { /// when a scan's accumulated data exceeds this limit, abort the scan pub scan_results_limit_bytes: Option, + pub purge_older_root_entries_one_slot_list: AtomicUsize, + /// # roots added since last check pub roots_added: AtomicUsize, /// # roots removed since last check @@ -690,6 +692,7 @@ impl + Into> AccountsIndex { .and_then(|config| config.scan_results_limit_bytes); let (account_maps, bin_calculator, storage) = Self::allocate_accounts_index(config, exit); Self { + purge_older_root_entries_one_slot_list: AtomicUsize::default(), account_maps, bin_calculator, program_id_index: SecondaryIndex::::new( @@ -1817,6 +1820,10 @@ impl + Into> AccountsIndex { reclaims: &mut SlotList, max_clean_root_inclusive: Option, ) { + if slot_list.len() <= 1 { + self.purge_older_root_entries_one_slot_list + .fetch_add(1, Ordering::Relaxed); + } let newest_root_in_slot_list; let max_clean_root_inclusive = { let roots_tracker = &self.roots_tracker.read().unwrap();