From 7214286221f5b8776c706fd37ed9a5ac0525b601 Mon Sep 17 00:00:00 2001 From: brooks Date: Thu, 21 Sep 2023 16:23:08 -0500 Subject: [PATCH] Uses `IntSet` for `ShrinkCandidates` --- accounts-db/src/accounts_db.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/accounts-db/src/accounts_db.rs b/accounts-db/src/accounts_db.rs index dad1f152f36de2..f028ad0daef810 100644 --- a/accounts-db/src/accounts_db.rs +++ b/accounts-db/src/accounts_db.rs @@ -80,6 +80,7 @@ use { rayon::{prelude::*, ThreadPool}, serde::{Deserialize, Serialize}, solana_measure::{measure::Measure, measure_us}, + solana_nohash_hasher::IntSet, solana_rayon_threadlimit::get_thread_count, solana_sdk::{ account::{Account, AccountSharedData, ReadableAccount, WritableAccount}, @@ -767,7 +768,7 @@ type AccountSlots = HashMap>; type SlotOffsets = HashMap>; type ReclaimResult = (AccountSlots, SlotOffsets); type PubkeysRemovedFromAccountsIndex = HashSet; -type ShrinkCandidates = HashSet; +type ShrinkCandidates = IntSet; // Some hints for applicability of additional sanity checks for the do_load fast-path; // Slower fallback code path will be taken if the fast path has failed over the retry @@ -2488,7 +2489,7 @@ impl AccountsDb { recycle_stores: RwLock::new(RecycleStores::default()), uncleaned_pubkeys: DashMap::new(), next_id: AtomicAppendVecId::new(0), - shrink_candidate_slots: Mutex::new(ShrinkCandidates::new()), + shrink_candidate_slots: Mutex::new(ShrinkCandidates::default()), write_cache_limit_bytes: None, write_version: AtomicU64::new(0), paths: vec![], @@ -4323,7 +4324,7 @@ 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 = HashMap::new(); - let mut shrink_slots_next_batch = ShrinkCandidates::new(); + let mut shrink_slots_next_batch = ShrinkCandidates::default(); for usage in &store_usage { let store = &usage.store; let alive_ratio = (total_alive_bytes as f64) / (total_bytes as f64); @@ -8176,7 +8177,7 @@ impl AccountsDb { assert!(self.storage.no_shrink_in_progress()); let mut dead_slots = HashSet::new(); - let mut new_shrink_candidates = ShrinkCandidates::new(); + let mut new_shrink_candidates = ShrinkCandidates::default(); let mut measure = Measure::start("remove"); for (slot, account_info) in reclaims { // No cached accounts should make it here @@ -13325,7 +13326,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 = ShrinkCandidates::new(); + let candidates = ShrinkCandidates::default(); let db = AccountsDb::new_single_for_tests(); let (selected_candidates, next_candidates) = @@ -13339,7 +13340,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::new(); + let mut candidates = ShrinkCandidates::default(); let db = AccountsDb::new_single_for_tests(); let common_store_path = Path::new(""); @@ -13413,7 +13414,7 @@ pub mod tests { // three candidates, 2 are selected for shrink, one is ignored solana_logger::setup(); let db = AccountsDb::new_single_for_tests(); - let mut candidates = ShrinkCandidates::new(); + let mut candidates = ShrinkCandidates::default(); let common_store_path = Path::new(""); let slot_id_1 = 12; @@ -13479,7 +13480,7 @@ pub mod tests { // 2 candidates, they must be selected to achieve the target alive ratio solana_logger::setup(); let db = AccountsDb::new_single_for_tests(); - let mut candidates = ShrinkCandidates::new(); + let mut candidates = ShrinkCandidates::default(); let slot1 = 12; let common_store_path = Path::new("");