Skip to content

Commit

Permalink
rework secondary index generation (#959)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington authored Apr 22, 2024
1 parent 1c28671 commit 7389371
Showing 1 changed file with 6 additions and 36 deletions.
42 changes: 6 additions & 36 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -8666,49 +8666,19 @@ 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(
pubkey,
&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
Expand Down

0 comments on commit 7389371

Please sign in to comment.