shink all in parallel on startup (#17308)
This commit is contained in:
committed by
GitHub
parent
ed9cbd50f0
commit
c20b27bc8f
@ -2171,7 +2171,16 @@ impl AccountsDb {
|
||||
num_candidates
|
||||
}
|
||||
|
||||
pub fn shrink_all_slots(&self) {
|
||||
pub fn shrink_all_slots(&self, is_startup: bool) {
|
||||
if is_startup && self.caching_enabled {
|
||||
let slots = self.all_slots_in_storage();
|
||||
let chunk_size = std::cmp::max(slots.len() / 8, 1); // approximately 400k slots in a snapshot
|
||||
slots.par_chunks(chunk_size).for_each(|slots| {
|
||||
for slot in slots {
|
||||
self.shrink_slot_forced(*slot);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
for slot in self.all_slots_in_storage() {
|
||||
if self.caching_enabled {
|
||||
self.shrink_slot_forced(slot);
|
||||
@ -2180,6 +2189,7 @@ impl AccountsDb {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn scan_accounts<F, A>(&self, ancestors: &Ancestors, scan_func: F) -> A
|
||||
where
|
||||
@ -8445,13 +8455,15 @@ pub mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_shrink_all_slots_none() {
|
||||
for startup in &[false, true] {
|
||||
let accounts = AccountsDb::new_single();
|
||||
|
||||
for _ in 0..10 {
|
||||
accounts.shrink_candidate_slots();
|
||||
}
|
||||
|
||||
accounts.shrink_all_slots();
|
||||
accounts.shrink_all_slots(*startup);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -8532,6 +8544,7 @@ pub mod tests {
|
||||
fn test_shrink_stale_slots_processed() {
|
||||
solana_logger::setup();
|
||||
|
||||
for startup in &[false, true] {
|
||||
let accounts = AccountsDb::new_single();
|
||||
|
||||
let pubkey_count = 100;
|
||||
@ -8571,7 +8584,7 @@ pub mod tests {
|
||||
pubkey_count,
|
||||
accounts.all_account_count_in_append_vec(shrink_slot)
|
||||
);
|
||||
accounts.shrink_all_slots();
|
||||
accounts.shrink_all_slots(*startup);
|
||||
assert_eq!(
|
||||
pubkey_count_after_shrink,
|
||||
accounts.all_account_count_in_append_vec(shrink_slot)
|
||||
@ -8589,12 +8602,13 @@ pub mod tests {
|
||||
.unwrap();
|
||||
|
||||
// repeating should be no-op
|
||||
accounts.shrink_all_slots();
|
||||
accounts.shrink_all_slots(*startup);
|
||||
assert_eq!(
|
||||
pubkey_count_after_shrink,
|
||||
accounts.all_account_count_in_append_vec(shrink_slot)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_shrink_candidate_slots() {
|
||||
@ -8648,7 +8662,7 @@ pub mod tests {
|
||||
);
|
||||
|
||||
// Now, do full-shrink.
|
||||
accounts.shrink_all_slots();
|
||||
accounts.shrink_all_slots(false);
|
||||
assert_eq!(
|
||||
pubkey_count_after_shrink,
|
||||
accounts.all_account_count_in_append_vec(shrink_slot)
|
||||
@ -8708,7 +8722,7 @@ pub mod tests {
|
||||
);
|
||||
|
||||
// Now, do full-shrink.
|
||||
accounts.shrink_all_slots();
|
||||
accounts.shrink_all_slots(false);
|
||||
assert_eq!(
|
||||
pubkey_count_after_shrink,
|
||||
accounts.all_account_count_in_append_vec(shrink_slot)
|
||||
@ -8910,7 +8924,7 @@ pub mod tests {
|
||||
}
|
||||
accounts.add_root(1);
|
||||
accounts.clean_accounts(None);
|
||||
accounts.shrink_all_slots();
|
||||
accounts.shrink_all_slots(false);
|
||||
accounts.print_accounts_stats("post-shrink");
|
||||
let num_stores = accounts.recycle_stores.read().unwrap().entry_count();
|
||||
assert!(num_stores > 0);
|
||||
|
@ -2122,7 +2122,7 @@ impl Bank {
|
||||
clean.stop();
|
||||
|
||||
let mut shrink = Measure::start("shrink");
|
||||
self.shrink_all_slots();
|
||||
self.shrink_all_slots(false);
|
||||
shrink.stop();
|
||||
|
||||
info!(
|
||||
@ -4527,7 +4527,7 @@ impl Bank {
|
||||
|
||||
let mut shrink_all_slots_time = Measure::start("shrink_all_slots");
|
||||
if self.slot() > 0 {
|
||||
self.shrink_all_slots();
|
||||
self.shrink_all_slots(true);
|
||||
}
|
||||
shrink_all_slots_time.stop();
|
||||
|
||||
@ -4816,8 +4816,8 @@ impl Bank {
|
||||
self.rc.accounts.accounts_db.clean_accounts(max_clean_slot);
|
||||
}
|
||||
|
||||
pub fn shrink_all_slots(&self) {
|
||||
self.rc.accounts.accounts_db.shrink_all_slots();
|
||||
pub fn shrink_all_slots(&self, is_startup: bool) {
|
||||
self.rc.accounts.accounts_db.shrink_all_slots(is_startup);
|
||||
}
|
||||
|
||||
pub fn print_accounts_stats(&self) {
|
||||
|
Reference in New Issue
Block a user