Skip to content

Commit

Permalink
refactor addref_accounts_failed_to_shrink_ancient (solana-labs#1562)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington authored Jun 3, 2024
1 parent 0c70735 commit fdf724e
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions accounts-db/src/ancient_append_vecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ impl AccountsDb {
accounts_to_combine.target_slots_sorted.last(),
many_refs_newest.last().map(|accounts| accounts.slot)
);
self.addref_accounts_failed_to_shrink_ancient(accounts_to_combine);
self.addref_accounts_failed_to_shrink_ancient(accounts_to_combine.accounts_to_combine);
return;
}

Expand All @@ -385,7 +385,7 @@ impl AccountsDb {
// Not enough slots to contain the accounts we are trying to pack.
// `shrink_collect` previously unref'd some accounts. We need to addref them
// to restore the correct state since we failed to combine anything.
self.addref_accounts_failed_to_shrink_ancient(accounts_to_combine);
self.addref_accounts_failed_to_shrink_ancient(accounts_to_combine.accounts_to_combine);
return;
}

Expand All @@ -399,24 +399,24 @@ impl AccountsDb {
}

/// for each account in `unrefed_pubkeys`, in each `accounts_to_combine`, addref
fn addref_accounts_failed_to_shrink_ancient(&self, accounts_to_combine: AccountsToCombine) {
fn addref_accounts_failed_to_shrink_ancient<'a>(
&self,
accounts_to_combine: Vec<ShrinkCollect<'a, ShrinkCollectAliveSeparatedByRefs<'a>>>,
) {
self.thread_pool_clean.install(|| {
accounts_to_combine
.accounts_to_combine
.into_par_iter()
.for_each(|combine| {
self.accounts_index.scan(
combine.unrefed_pubkeys.into_iter(),
|_pubkey, _slots_refs, entry| {
if let Some(entry) = entry {
entry.addref();
}
AccountsIndexScanResult::OnlyKeepInMemoryIfDirty
},
None,
true,
);
});
accounts_to_combine.into_par_iter().for_each(|combine| {
self.accounts_index.scan(
combine.unrefed_pubkeys.into_iter(),
|_pubkey, _slots_refs, entry| {
if let Some(entry) = entry {
entry.addref();
}
AccountsIndexScanResult::OnlyKeepInMemoryIfDirty
},
None,
true,
);
});
});
}

Expand Down Expand Up @@ -3413,7 +3413,7 @@ pub mod tests {
target_slots_sorted: Vec::default(),
unpackable_slots_count: 0,
};
db.addref_accounts_failed_to_shrink_ancient(accounts_to_combine);
db.addref_accounts_failed_to_shrink_ancient(accounts_to_combine.accounts_to_combine);
db.accounts_index.scan(
unrefed_pubkeys.iter(),
|k, slot_refs, _entry| {
Expand Down

0 comments on commit fdf724e

Please sign in to comment.