Skip to content

Commit

Permalink
extract common code remove_old_stores_shrink from shrink and ancient …
Browse files Browse the repository at this point in the history
…append vecs (solana-labs#28588)
  • Loading branch information
jeffwashington authored Oct 26, 2022
1 parent 27269d8 commit d4db649
Showing 1 changed file with 35 additions and 40 deletions.
75 changes: 35 additions & 40 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3811,6 +3811,37 @@ impl AccountsDb {
}
}

/// common code from shrink and combine_ancient_slots
/// returns (remaining stores, measure of time to mark stores dirty or dead)
fn remove_old_stores_shrink(
&self,
keep_store_ids: &[AppendVecId],
shrink_collect: &ShrinkCollect,
slot: Slot,
) -> (usize, Measure) {
let mut write_storage_elapsed = Measure::start("mark_dirty_dead_stores");
// Purge old, overwritten storage entries
let (remaining_stores, dead_storages) = self.mark_dirty_dead_stores(
slot,
|store| !keep_store_ids.contains(&store.append_vec_id()),
// If all accounts are zero lamports, then we want to mark the entire OLD append vec as dirty.
// otherwise, we'll call 'add_uncleaned_pubkeys_after_shrink' just on the unref'd keys below.
shrink_collect.all_are_zero_lamports,
);

if !shrink_collect.all_are_zero_lamports {
self.add_uncleaned_pubkeys_after_shrink(
slot,
shrink_collect.unrefed_pubkeys.iter().cloned().cloned(),
);
}

write_storage_elapsed.stop();

self.drop_or_recycle_stores(dead_storages);
(remaining_stores, write_storage_elapsed)
}

fn do_shrink_slot_stores<'a, I>(&'a self, slot: Slot, stores: I) -> usize
where
I: Iterator<Item = &'a Arc<AccountStorageEntry>>,
Expand Down Expand Up @@ -3892,28 +3923,10 @@ impl AccountsDb {
// those here
self.shrink_candidate_slots.lock().unwrap().remove(&slot);

let mut write_storage_elapsed = Measure::start("mark_dirty_dead_stores");
// Purge old, overwritten storage entries
let (remaining_stores, dead_storages) = self.mark_dirty_dead_stores(
slot,
|store| !shrink_collect.store_ids.contains(&store.append_vec_id()),
// If all accounts are zero lamports, then we want to mark the entire OLD append vec as dirty.
// otherwise, we'll call 'add_uncleaned_pubkeys_after_shrink' just on the unref'd keys below.
shrink_collect.all_are_zero_lamports,
);

if !shrink_collect.all_are_zero_lamports {
self.add_uncleaned_pubkeys_after_shrink(
slot,
shrink_collect.unrefed_pubkeys.iter().cloned().cloned(),
);
}

write_storage_elapsed.stop();
let (remaining_stores, write_storage_elapsed) =
self.remove_old_stores_shrink(&shrink_collect.store_ids, &shrink_collect, slot);
write_storage_elapsed_us = write_storage_elapsed.as_us();

self.drop_or_recycle_stores(dead_storages);

if remaining_stores > 1 {
inc_new_counter_info!("accounts_db_shrink_extra_stores", 1);
info!(
Expand Down Expand Up @@ -4449,26 +4462,8 @@ impl AccountsDb {
}
rewrite_elapsed.stop();

let mut write_storage_elapsed = Measure::start("mark_dirty_dead_stores");
// Purge old, overwritten storage entries
let (_, dead_storages) = self.mark_dirty_dead_stores(
slot,
|store| ids.contains(&store.append_vec_id()),
// If all accounts are zero lamports, then we want to mark the entire OLD append vec as dirty.
// otherwise, we'll call 'add_uncleaned_pubkeys_after_shrink' just on the unref'd keys below.
shrink_collect.all_are_zero_lamports,
);

if !shrink_collect.all_are_zero_lamports {
self.add_uncleaned_pubkeys_after_shrink(
slot,
shrink_collect.unrefed_pubkeys.iter().cloned().cloned(),
);
}

write_storage_elapsed.stop();

self.drop_or_recycle_stores(dead_storages);
let (_remaining_stores, write_storage_elapsed) =
self.remove_old_stores_shrink(&ids, &shrink_collect, slot);

if drop_root {
dropped_roots.push(slot);
Expand Down

0 comments on commit d4db649

Please sign in to comment.