Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: check for all zeros on startup #2880

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,8 @@ pub struct AccountsDb {
/// Set of shrinkable stores organized by map of slot to storage id
pub shrink_candidate_slots: Mutex<ShrinkCandidates>,

pub force_shrink_candidate_slots: Mutex<ShrinkCandidates>,

pub write_version: AtomicU64,

/// Set of storage paths to pick from
Expand Down Expand Up @@ -2510,6 +2512,7 @@ impl AccountsDb {
uncleaned_pubkeys: DashMap::new(),
next_id: AtomicAccountsFileId::new(0),
shrink_candidate_slots: Mutex::new(ShrinkCandidates::default()),
force_shrink_candidate_slots: Mutex::new(ShrinkCandidates::default()),
write_cache_limit_bytes: None,
write_version: AtomicU64::new(0),
paths: vec![],
Expand Down Expand Up @@ -5061,7 +5064,7 @@ impl AccountsDb {
let shrink_candidates_slots =
std::mem::take(&mut *self.shrink_candidate_slots.lock().unwrap());

let (shrink_slots, shrink_slots_next_batch) = {
let (mut shrink_slots, shrink_slots_next_batch) = {
if let AccountShrinkThreshold::TotalSpace { shrink_ratio } = self.shrink_ratio {
let (shrink_slots, shrink_slots_next_batch) =
self.select_candidates_by_total_usage(&shrink_candidates_slots, shrink_ratio);
Expand All @@ -5082,6 +5085,21 @@ impl AccountsDb {
}
};

let force_shrink_candidates_slots =
std::mem::take(&mut *self.shrink_candidate_slots.lock().unwrap());

if !force_shrink_candidates_slots.is_empty() {
shrink_slots.extend(
force_shrink_candidates_slots
.into_iter()
.filter_map(|slot| {
self.storage
.get_slot_storage_entry(slot)
.map(|storage| (slot, storage))
}),
)
}

if shrink_slots.is_empty()
&& shrink_slots_next_batch
.as_ref()
Expand Down Expand Up @@ -8836,7 +8854,7 @@ impl AccountsDb {

fn generate_index_for_slot(
&self,
storage: &AccountStorageEntry,
storage: &Arc<AccountStorageEntry>,
slot: Slot,
store_id: AccountsFileId,
rent_collector: &RentCollector,
Expand All @@ -8853,15 +8871,27 @@ impl AccountsDb {
let mut amount_to_top_off_rent = 0;
let mut stored_size_alive = 0;

let mut all_accounts_are_zero_lamports = true;

let (dirty_pubkeys, insert_time_us, mut generate_index_results) = {
let mut items_local = Vec::default();
storage.accounts.scan_index(|info| {
stored_size_alive += info.stored_size_aligned;
if info.index_info.lamports > 0 {
accounts_data_len += info.index_info.data_len;
all_accounts_are_zero_lamports = false;
}
items_local.push(info.index_info);
});
if all_accounts_are_zero_lamports {
// this whole slot can likely be marked dead and dropped. Clean has to determine that. There could be an older non-zero account for any of these zero lamport accounts.
self.dirty_stores.insert(slot, Arc::clone(storage));
self.accounts_index.add_uncleaned_roots([slot].into_iter());
self.force_shrink_candidate_slots
.lock()
.unwrap()
.insert(slot);
}
let items = items_local.into_iter().map(|info| {
if let Some(amount_to_top_off_rent_this_account) = Self::stats_for_rent_payers(
&info.pubkey,
Expand Down
Loading