From 4e53cf6a81375d5b0f0831a059337a8a38a41e0f Mon Sep 17 00:00:00 2001 From: HaoranYi Date: Thu, 17 Oct 2024 18:55:04 +0000 Subject: [PATCH] wait to add zero slot to clean after index flush --- accounts-db/src/accounts_db.rs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index 92921c270c9f3b..ea7c3f8f197ba9 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -8282,7 +8282,7 @@ impl AccountsDb { fn generate_index_for_slot( &self, - storage: &Arc, + storage: &AccountStorageEntry, slot: Slot, store_id: AccountsFileId, rent_collector: &RentCollector, @@ -8311,13 +8311,6 @@ impl AccountsDb { items_local.push(info.index_info); }); - if all_accounts_are_zero_lamports { - // this whole slot can likely be marked dead and dropped. Clean - // has to determine that. There could be an older non-zero - // account for any of these zero lamport accounts. - self.dirty_stores.insert(slot, Arc::clone(storage)); - self.accounts_index.add_uncleaned_roots([slot]); - } let items_len = items_local.len(); let items = items_local.into_iter().map(|info| { if let Some(amount_to_top_off_rent_this_account) = Self::stats_for_rent_payers( @@ -8454,6 +8447,7 @@ impl AccountsDb { let amount_to_top_off_rent = AtomicU64::new(0); let total_including_duplicates = AtomicU64::new(0); let all_accounts_are_zero_lamports_slots = AtomicU64::new(0); + let all_zeros_slots = Mutex::new(Vec::<(Slot, Arc)>::new()); let scan_time: u64 = slots .par_chunks(chunk_size) .map(|slots| { @@ -8514,6 +8508,13 @@ impl AccountsDb { rent_paying_accounts_by_partition.add_account(k); }); + if all_accounts_are_zero_lamports { + all_zeros_slots + .lock() + .unwrap() + .push((*slot, Arc::clone(&storage))); + } + insert_us } else { // verify index matches expected and measure the time to get all items @@ -8720,6 +8721,16 @@ impl AccountsDb { "accounts data len: {}", accounts_data_len.load(Ordering::Relaxed) ); + + let all_zero_slots_to_clean = std::mem::take(&mut *all_zeros_slots.lock().unwrap()); + info!( + "insert all zero slots to clean at startup {}", + all_zero_slots_to_clean.len() + ); + for (slot, storage) in all_zero_slots_to_clean { + self.dirty_stores.insert(slot, storage); + self.accounts_index.add_uncleaned_roots([slot]); + } } if pass == 0 {