diff --git a/core/tests/snapshots.rs b/core/tests/snapshots.rs index 17774f2df7309c..3f7334785d2f9d 100644 --- a/core/tests/snapshots.rs +++ b/core/tests/snapshots.rs @@ -473,7 +473,7 @@ fn test_concurrent_snapshot_packaging( // Purge all the outdated snapshots, including the ones needed to generate the package // currently sitting in the channel - snapshot_utils::purge_old_bank_snapshots(bank_snapshots_dir, MAX_BANK_SNAPSHOTS_TO_RETAIN); + snapshot_utils::purge_old_bank_snapshots(bank_snapshots_dir, MAX_BANK_SNAPSHOTS_TO_RETAIN, None); let mut bank_snapshots = snapshot_utils::get_bank_snapshots_pre(bank_snapshots_dir); bank_snapshots.sort_unstable(); diff --git a/local-cluster/tests/local_cluster.rs b/local-cluster/tests/local_cluster.rs index 4da00315fc5215..7d323b1de9638f 100644 --- a/local-cluster/tests/local_cluster.rs +++ b/local-cluster/tests/local_cluster.rs @@ -1102,7 +1102,7 @@ fn test_incremental_snapshot_download_with_crossing_full_snapshot_interval_at_st // To restart, it is not enough to remove the old bank snapshot directories under snapshot/. // The old hardlinks under /snapshot/ should also be removed. // The purge call covers all of them. - snapshot_utils::purge_old_bank_snapshots(validator_snapshot_test_config.bank_snapshots_dir, 0); + snapshot_utils::purge_old_bank_snapshots(validator_snapshot_test_config.bank_snapshots_dir, 0, None); cluster.restart_node( &validator_identity.pubkey(), validator_info, diff --git a/runtime/src/accounts_background_service.rs b/runtime/src/accounts_background_service.rs index c5e8afc540c416..15d5a64cfd3552 100644 --- a/runtime/src/accounts_background_service.rs +++ b/runtime/src/accounts_background_service.rs @@ -402,6 +402,7 @@ impl SnapshotRequestHandler { snapshot_utils::purge_old_bank_snapshots( &self.snapshot_config.bank_snapshots_dir, MAX_BANK_SNAPSHOTS_TO_RETAIN, + None, ); purge_old_snapshots_time.stop(); total_time.stop(); diff --git a/runtime/src/snapshot_utils.rs b/runtime/src/snapshot_utils.rs index 49635d2a42aaac..6369e2b3ea6a58 100644 --- a/runtime/src/snapshot_utils.rs +++ b/runtime/src/snapshot_utils.rs @@ -2882,6 +2882,7 @@ pub fn verify_snapshot_archive( pub fn purge_old_bank_snapshots( bank_snapshots_dir: impl AsRef, num_bank_snapshots_to_retain: usize, + type_select: Option, ) { let do_purge = |mut bank_snapshots: Vec| { bank_snapshots.sort_unstable(); @@ -2900,8 +2901,18 @@ pub fn purge_old_bank_snapshots( }) }; - do_purge(get_bank_snapshots_pre(&bank_snapshots_dir)); - do_purge(get_bank_snapshots_post(&bank_snapshots_dir)); + match type_select { + Some(BankSnapshotType::Pre) => { + do_purge(get_bank_snapshots_pre(&bank_snapshots_dir)); + } + Some(BankSnapshotType::Post) => { + do_purge(get_bank_snapshots_post(&bank_snapshots_dir)); + } + None => { + do_purge(get_bank_snapshots_pre(&bank_snapshots_dir)); + do_purge(get_bank_snapshots_post(&bank_snapshots_dir)); + } + } } /// Get the snapshot storages for this bank