AccountsHashVerifier purges old accounts hashes (#30644)

This commit is contained in:
Brooks 2023-03-13 11:12:11 -04:00 committed by GitHub
parent 5e5b7f00a2
commit a43f803604
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

View File

@ -314,11 +314,16 @@ impl AccountsHashVerifier {
if accounts_package.package_type if accounts_package.package_type
== AccountsPackageType::Snapshot(SnapshotType::FullSnapshot) == AccountsPackageType::Snapshot(SnapshotType::FullSnapshot)
{ {
let last_full_snapshot_slot = accounts_package.slot;
*last_full_snapshot = Some(FullSnapshotAccountsHashInfo { *last_full_snapshot = Some(FullSnapshotAccountsHashInfo {
slot: accounts_package.slot, slot: last_full_snapshot_slot,
accounts_hash, accounts_hash,
capitalization: lamports, capitalization: lamports,
}); });
accounts_package
.accounts
.accounts_db
.purge_old_accounts_hashes(last_full_snapshot_slot);
} }
datapoint_info!( datapoint_info!(

View File

@ -7379,6 +7379,17 @@ impl AccountsDb {
self.accounts_hashes.lock().unwrap().get(&slot).cloned() self.accounts_hashes.lock().unwrap().get(&slot).cloned()
} }
/// Purge accounts hashes that are older than `last_full_snapshot_slot`
///
/// Should only be called by AccountsHashVerifier, since it consumes `account_hashes` and knows
/// which ones are still needed.
pub fn purge_old_accounts_hashes(&self, last_full_snapshot_slot: Slot) {
self.accounts_hashes
.lock()
.unwrap()
.retain(|&slot, _| slot >= last_full_snapshot_slot);
}
/// scan 'storages', return a vec of 'CacheHashDataFile', one per pass /// scan 'storages', return a vec of 'CacheHashDataFile', one per pass
fn scan_snapshot_stores_with_cache( fn scan_snapshot_stores_with_cache(
&self, &self,
@ -7827,16 +7838,14 @@ impl AccountsDb {
/// Remove "bank hash info" for `slots` /// Remove "bank hash info" for `slots`
/// ///
/// This fn removes the accounts delta hash, accounts hash, and bank hash stats for `slots` from /// This fn removes the accounts delta hash and bank hash stats for `slots` from
/// their respective maps. /// their respective maps.
fn remove_bank_hash_infos<'s>(&self, slots: impl IntoIterator<Item = &'s Slot>) { fn remove_bank_hash_infos<'s>(&self, slots: impl IntoIterator<Item = &'s Slot>) {
let mut accounts_delta_hashes = self.accounts_delta_hashes.lock().unwrap(); let mut accounts_delta_hashes = self.accounts_delta_hashes.lock().unwrap();
let mut accounts_hashes = self.accounts_hashes.lock().unwrap();
let mut bank_hash_stats = self.bank_hash_stats.lock().unwrap(); let mut bank_hash_stats = self.bank_hash_stats.lock().unwrap();
for slot in slots.into_iter() { for slot in slots {
accounts_delta_hashes.remove(slot); accounts_delta_hashes.remove(slot);
accounts_hashes.remove(slot);
bank_hash_stats.remove(slot); bank_hash_stats.remove(slot);
} }
} }
@ -12629,7 +12638,7 @@ pub mod tests {
Ok(_) Ok(_)
); );
db.remove_bank_hash_info(&some_slot); db.accounts_hashes.lock().unwrap().remove(&some_slot);
assert_matches!( assert_matches!(
db.verify_accounts_hash_and_lamports(some_slot, 1, config.clone()), db.verify_accounts_hash_and_lamports(some_slot, 1, config.clone()),