Do not keep oldest full snapshot
This commit is contained in:
parent
d0d256ee9a
commit
72c68695b5
|
@ -1259,9 +1259,7 @@ pub fn purge_old_snapshot_archives<P>(
|
||||||
let mut snapshot_archives = get_full_snapshot_archives(&snapshot_archives_dir);
|
let mut snapshot_archives = get_full_snapshot_archives(&snapshot_archives_dir);
|
||||||
snapshot_archives.sort_unstable();
|
snapshot_archives.sort_unstable();
|
||||||
snapshot_archives.reverse();
|
snapshot_archives.reverse();
|
||||||
// Keep the oldest snapshot so we can always play the ledger from it.
|
let max_snaps = max(1, maximum_full_snapshot_archives_to_retain); // Always keep at least one snapshot
|
||||||
snapshot_archives.pop();
|
|
||||||
let max_snaps = max(1, maximum_full_snapshot_archives_to_retain);
|
|
||||||
for old_archive in snapshot_archives.into_iter().skip(max_snaps) {
|
for old_archive in snapshot_archives.into_iter().skip(max_snaps) {
|
||||||
trace!(
|
trace!(
|
||||||
"Purging old full snapshot archive: {}",
|
"Purging old full snapshot archive: {}",
|
||||||
|
@ -2427,20 +2425,24 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
for snap_name in expected_snapshots {
|
for snap_name in expected_snapshots {
|
||||||
assert!(retained_snaps.contains(snap_name.as_str()));
|
assert!(
|
||||||
|
retained_snaps.contains(snap_name.as_str()),
|
||||||
|
"{} not found",
|
||||||
|
snap_name
|
||||||
|
);
|
||||||
}
|
}
|
||||||
assert!(retained_snaps.len() == expected_snapshots.len());
|
assert!(retained_snaps.len() == expected_snapshots.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_purge_old_full_snapshot_archives() {
|
fn test_purge_old_full_snapshot_archives() {
|
||||||
// Create 3 snapshots, retaining 1,
|
|
||||||
// expecting the oldest 1 and the newest 1 are retained
|
|
||||||
let snap1_name = format!("snapshot-1-{}.tar.zst", Hash::default());
|
let snap1_name = format!("snapshot-1-{}.tar.zst", Hash::default());
|
||||||
let snap2_name = format!("snapshot-3-{}.tar.zst", Hash::default());
|
let snap2_name = format!("snapshot-3-{}.tar.zst", Hash::default());
|
||||||
let snap3_name = format!("snapshot-50-{}.tar.zst", Hash::default());
|
let snap3_name = format!("snapshot-50-{}.tar.zst", Hash::default());
|
||||||
let snapshot_names = vec![&snap1_name, &snap2_name, &snap3_name];
|
let snapshot_names = vec![&snap1_name, &snap2_name, &snap3_name];
|
||||||
let expected_snapshots = vec![&snap1_name, &snap3_name];
|
|
||||||
|
// expecting only the newest to be retained
|
||||||
|
let expected_snapshots = vec![&snap3_name];
|
||||||
common_test_purge_old_snapshot_archives(
|
common_test_purge_old_snapshot_archives(
|
||||||
&snapshot_names,
|
&snapshot_names,
|
||||||
1,
|
1,
|
||||||
|
@ -2448,7 +2450,7 @@ mod tests {
|
||||||
&expected_snapshots,
|
&expected_snapshots,
|
||||||
);
|
);
|
||||||
|
|
||||||
// retaining 0, the expectation is the same as for 1, as at least 1 newest is expected to be retained
|
// retaining 0, but minimum to retain is 1
|
||||||
common_test_purge_old_snapshot_archives(
|
common_test_purge_old_snapshot_archives(
|
||||||
&snapshot_names,
|
&snapshot_names,
|
||||||
0,
|
0,
|
||||||
|
@ -2456,14 +2458,23 @@ mod tests {
|
||||||
&expected_snapshots,
|
&expected_snapshots,
|
||||||
);
|
);
|
||||||
|
|
||||||
// retaining 2, all three should be retained
|
// retaiing 2, expecting the 2 newest to be retained
|
||||||
let expected_snapshots = vec![&snap1_name, &snap2_name, &snap3_name];
|
let expected_snapshots = vec![&snap2_name, &snap3_name];
|
||||||
common_test_purge_old_snapshot_archives(
|
common_test_purge_old_snapshot_archives(
|
||||||
&snapshot_names,
|
&snapshot_names,
|
||||||
2,
|
2,
|
||||||
DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
|
DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
|
||||||
&expected_snapshots,
|
&expected_snapshots,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// retaining 3, all three should be retained
|
||||||
|
let expected_snapshots = vec![&snap1_name, &snap2_name, &snap3_name];
|
||||||
|
common_test_purge_old_snapshot_archives(
|
||||||
|
&snapshot_names,
|
||||||
|
3,
|
||||||
|
DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
|
||||||
|
&expected_snapshots,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mimic a running node's behavior w.r.t. purging old snapshot archives. Take snapshots in a
|
/// Mimic a running node's behavior w.r.t. purging old snapshot archives. Take snapshots in a
|
||||||
|
@ -2500,18 +2511,9 @@ mod tests {
|
||||||
);
|
);
|
||||||
let mut full_snapshot_archives = get_full_snapshot_archives(&snapshot_archives_dir);
|
let mut full_snapshot_archives = get_full_snapshot_archives(&snapshot_archives_dir);
|
||||||
full_snapshot_archives.sort_unstable();
|
full_snapshot_archives.sort_unstable();
|
||||||
assert_eq!(
|
assert_eq!(full_snapshot_archives.len(), maximum_snapshots_to_retain,);
|
||||||
full_snapshot_archives.len(),
|
|
||||||
maximum_snapshots_to_retain + 1
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
full_snapshot_archives.first().unwrap().slot(),
|
|
||||||
starting_slot
|
|
||||||
);
|
|
||||||
assert_eq!(full_snapshot_archives.last().unwrap().slot(), slot);
|
assert_eq!(full_snapshot_archives.last().unwrap().slot(), slot);
|
||||||
for (i, full_snapshot_archive) in
|
for (i, full_snapshot_archive) in full_snapshot_archives.iter().rev().enumerate() {
|
||||||
full_snapshot_archives.iter().skip(1).rev().enumerate()
|
|
||||||
{
|
|
||||||
assert_eq!(full_snapshot_archive.slot(), slot - i as Slot);
|
assert_eq!(full_snapshot_archive.slot(), slot - i as Slot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2572,7 +2574,7 @@ mod tests {
|
||||||
get_full_snapshot_archives(snapshot_archives_dir.path());
|
get_full_snapshot_archives(snapshot_archives_dir.path());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
remaining_full_snapshot_archives.len(),
|
remaining_full_snapshot_archives.len(),
|
||||||
maximum_full_snapshot_archives_to_retain + 1,
|
maximum_full_snapshot_archives_to_retain,
|
||||||
);
|
);
|
||||||
remaining_full_snapshot_archives.sort_unstable();
|
remaining_full_snapshot_archives.sort_unstable();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue