Skip to content

Commit

Permalink
Add a type_select param for purge_old_bank_snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangzhu70 committed Apr 13, 2023
1 parent 1f67591 commit f88f84f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion local-cluster/tests/local_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <account_path>/snapshot/<slot> 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,
Expand Down
1 change: 1 addition & 0 deletions runtime/src/accounts_background_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 13 additions & 2 deletions runtime/src/snapshot_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2882,6 +2882,7 @@ pub fn verify_snapshot_archive<P, Q, R>(
pub fn purge_old_bank_snapshots(
bank_snapshots_dir: impl AsRef<Path>,
num_bank_snapshots_to_retain: usize,
type_select: Option<BankSnapshotType>,
) {
let do_purge = |mut bank_snapshots: Vec<BankSnapshotInfo>| {
bank_snapshots.sort_unstable();
Expand All @@ -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
Expand Down

0 comments on commit f88f84f

Please sign in to comment.