Skip to content

Commit

Permalink
remove coupling of ShrinkCandidates to HashMap
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwashington committed Sep 7, 2023
1 parent f4816dc commit 11ed144
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
14 changes: 7 additions & 7 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4311,8 +4311,8 @@ impl AccountsDb {

// Working from the beginning of store_usage which are the most sparse and see when we can stop
// shrinking while still achieving the overall goals.
let mut shrink_slots: ShrinkCandidates = HashMap::new();
let mut shrink_slots_next_batch: ShrinkCandidates = HashMap::new();
let mut shrink_slots = ShrinkCandidates::new();
let mut shrink_slots_next_batch = ShrinkCandidates::new();
for usage in &store_usage {
let store = &usage.store;
let alive_ratio = (total_alive_bytes as f64) / (total_bytes as f64);
Expand Down Expand Up @@ -8161,7 +8161,7 @@ impl AccountsDb {
assert!(self.storage.no_shrink_in_progress());

let mut dead_slots = HashSet::new();
let mut new_shrink_candidates: ShrinkCandidates = HashMap::new();
let mut new_shrink_candidates = ShrinkCandidates::new();
let mut measure = Measure::start("remove");
for (slot, account_info) in reclaims {
// No cached accounts should make it here
Expand Down Expand Up @@ -13250,7 +13250,7 @@ pub mod tests {
fn test_select_candidates_by_total_usage_no_candidates() {
// no input candidates -- none should be selected
solana_logger::setup();
let candidates: ShrinkCandidates = HashMap::new();
let candidates = ShrinkCandidates::new();

let (selected_candidates, next_candidates) = AccountsDb::select_candidates_by_total_usage(
&candidates,
Expand All @@ -13266,7 +13266,7 @@ pub mod tests {
fn test_select_candidates_by_total_usage_3_way_split_condition() {
// three candidates, one selected for shrink, one is put back to the candidate list and one is ignored
solana_logger::setup();
let mut candidates: ShrinkCandidates = HashMap::new();
let mut candidates = ShrinkCandidates::new();

let common_store_path = Path::new("");
let slot_id_1 = 12;
Expand Down Expand Up @@ -13340,7 +13340,7 @@ pub mod tests {
fn test_select_candidates_by_total_usage_2_way_split_condition() {
// three candidates, 2 are selected for shrink, one is ignored
solana_logger::setup();
let mut candidates: ShrinkCandidates = HashMap::new();
let mut candidates = ShrinkCandidates::new();

let common_store_path = Path::new("");
let slot_id_1 = 12;
Expand Down Expand Up @@ -13410,7 +13410,7 @@ pub mod tests {
fn test_select_candidates_by_total_usage_all_clean() {
// 2 candidates, they must be selected to achieve the target alive ratio
solana_logger::setup();
let mut candidates: ShrinkCandidates = HashMap::new();
let mut candidates = ShrinkCandidates::new();

let slot1 = 12;
let common_store_path = Path::new("");
Expand Down
24 changes: 15 additions & 9 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5951,14 +5951,14 @@ impl Bank {
mut accounts: Vec<(Pubkey, AccountSharedData, Slot)>,
rent_paying_pubkeys: Option<&HashSet<Pubkey>>,
partition_index: PartitionIndex,
can_skip_rewrites: bool,
) -> CollectRentFromAccountsInfo {
let mut rent_debits = RentDebits::default();
let mut total_rent_collected_info = CollectedInfo::default();
let mut accounts_to_store =
Vec::<(&Pubkey, &AccountSharedData)>::with_capacity(accounts.len());
let mut time_collecting_rent_us = 0;
let mut time_storing_accounts_us = 0;
let can_skip_rewrites = self.bank_hash_skips_rent_rewrites();
let set_exempt_rent_epoch_max: bool = self
.feature_set
.is_active(&solana_sdk::feature_set::set_exempt_rent_epoch_max::id());
Expand Down Expand Up @@ -6104,9 +6104,9 @@ impl Bank {
let end_prefix_inclusive = accounts_partition::prefix_from_pubkey(subrange_full.end());
let range = end_prefix_inclusive - start_prefix;
let increment = range / num_threads;
let mut results = (0..num_threads)
.into_par_iter()
.map(|chunk| {
let mut results = if can_skip_rewrites {
} else {
(0..num_threads).into_par_iter().map(|chunk| {
let offset = |chunk| start_prefix + chunk * increment;
let start = offset(chunk);
let last = chunk == num_threads - 1;
Expand All @@ -6129,14 +6129,20 @@ impl Bank {
.load_to_collect_rent_eagerly(&self.ancestors, subrange)
});
CollectRentInPartitionInfo::new(
self.collect_rent_from_accounts(accounts, rent_paying_pubkeys, partition.1),
self.collect_rent_from_accounts(
accounts,
rent_paying_pubkeys,
partition.1,
can_skip_rewrites,
),
Duration::from_nanos(measure_load_accounts.as_ns()),
)
})
.reduce(
CollectRentInPartitionInfo::default,
CollectRentInPartitionInfo::reduce,
);
}
.reduce(
CollectRentInPartitionInfo::default,
CollectRentInPartitionInfo::reduce,
);

// We cannot assert here that we collected from all expected keys.
// Some accounts may have been topped off or may have had all funds removed and gone to 0 lamports.
Expand Down

0 comments on commit 11ed144

Please sign in to comment.