Uses `IntSet` for `ShrinkCandidates` (#33522)

This commit is contained in:
Brooks 2023-10-04 13:07:35 -04:00 committed by GitHub
parent a25bb2e303
commit d41fa346cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 8 deletions

View File

@ -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<Pubkey, HashSet<Slot>>;
type SlotOffsets = HashMap<Slot, HashSet<usize>>;
type ReclaimResult = (AccountSlots, SlotOffsets);
type PubkeysRemovedFromAccountsIndex = HashSet<Pubkey>;
type ShrinkCandidates = HashSet<Slot>;
type ShrinkCandidates = IntSet<Slot>;
// 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("");