From 7389371112dbf082b78a661756f55df4306ccfa0 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Mon, 22 Apr 2024 12:59:47 -0500 Subject: [PATCH] rework secondary index generation (#959) --- accounts-db/src/accounts_db.rs | 42 +++++----------------------------- 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index 9070cf4def7350..802a8e1bc0af3d 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -8628,7 +8628,7 @@ impl AccountsDb { let mut amount_to_top_off_rent = 0; let mut stored_size_alive = 0; - let (dirty_pubkeys, insert_time_us, mut generate_index_results) = if !secondary { + let (dirty_pubkeys, insert_time_us, mut generate_index_results) = { let mut items_local = Vec::default(); storage.accounts.scan_index(|info| { stored_size_alive += info.stored_size_aligned; @@ -8666,9 +8666,10 @@ impl AccountsDb { storage.approx_stored_count(), items, ) - } else { - let accounts = storage.accounts.account_iter(); - let items = accounts.map(|stored_account| { + }; + if secondary { + // scan storage a second time to update the secondary index + storage.accounts.scan_accounts(|stored_account| { stored_size_alive += stored_account.stored_size(); let pubkey = stored_account.pubkey(); self.accounts_index.update_secondary_indexes( @@ -8676,39 +8677,8 @@ impl AccountsDb { &stored_account, &self.account_indexes, ); - if !stored_account.is_zero_lamport() { - accounts_data_len += stored_account.data().len() as u64; - } - - if let Some(amount_to_top_off_rent_this_account) = Self::stats_for_rent_payers( - pubkey, - stored_account.lamports(), - stored_account.data().len(), - stored_account.rent_epoch(), - stored_account.executable(), - rent_collector, - ) { - amount_to_top_off_rent += amount_to_top_off_rent_this_account; - num_accounts_rent_paying += 1; - // remember this rent-paying account pubkey - rent_paying_accounts_by_partition.push(*pubkey); - } - - ( - *pubkey, - AccountInfo::new( - StorageLocation::AppendVec(store_id, stored_account.offset()), // will never be cached - stored_account.lamports(), - ), - ) }); - self.accounts_index - .insert_new_if_missing_into_primary_index( - slot, - storage.approx_stored_count(), - items, - ) - }; + } if let Some(duplicates_this_slot) = std::mem::take(&mut generate_index_results.duplicates) { // there were duplicate pubkeys in this same slot