Skip to content

Commit

Permalink
Uses IntSet for ShrinkCandidates (solana-labs#33522)
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored Oct 4, 2023
1 parent a25bb2e commit d41fa34
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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![],
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) =
Expand All @@ -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("");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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("");
Expand Down

0 comments on commit d41fa34

Please sign in to comment.