fix: restore safety copies no longer compete with production captures in retention
A safety copy of a restore target was stored in the application's orbit and weighed by the same retention as captures, so the newest copy (the target's) could push the production capture that had just been restored out of the keep set, whatever the rule (GFS, count or age). Safety copies are now separated: they have their own per-target rule (newest three plus anything under seven days) and never count for or against captures. Proven red on the old behaviour with a real refresh. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1644,3 +1644,61 @@ async fn a_failure_reason_is_only_kept_for_failures_and_is_cleaned_and_bounded()
|
||||
"{reason:?}"
|
||||
);
|
||||
}
|
||||
|
||||
// ---- retention: a safety copy of the target is not a backup of production ----
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_restore_safety_copy_never_pushes_a_production_capture_out_of_retention() {
|
||||
use tessera_core::decay::CaptureRetention;
|
||||
let lab = fresh().await;
|
||||
// the harshest rule: only the newest archive is kept
|
||||
lab.state
|
||||
.db
|
||||
.update_capture_profile(
|
||||
lab.application,
|
||||
crate::db::ProfileChange {
|
||||
schedule: None,
|
||||
retention: Some(Some(CaptureRetention::Count { keep: 1 })),
|
||||
},
|
||||
now(),
|
||||
)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
lab.start(&lab.admin(), "safety-retention").await;
|
||||
let capture = lab
|
||||
.capture(&Lab::production_identity(), false)
|
||||
.await
|
||||
.unwrap();
|
||||
lab.tick().await;
|
||||
// the target's safety copy is taken later than the production capture
|
||||
tokio::time::sleep(std::time::Duration::from_millis(1200)).await;
|
||||
let (job, token) = lab.restore_until_ready().await.unwrap();
|
||||
assert_eq!(lab.apply(&job, &token).await, StatusCode::NO_CONTENT);
|
||||
lab.report_applied(&job, &token).await;
|
||||
lab.tick().await;
|
||||
|
||||
let snapshots = lab.state.vault.read().await.list_snapshots().unwrap();
|
||||
let safety: Vec<_> = snapshots
|
||||
.iter()
|
||||
.filter(|s| s.manifest.is_restore_safety())
|
||||
.map(|s| s.id)
|
||||
.collect();
|
||||
assert_eq!(
|
||||
safety.len(),
|
||||
1,
|
||||
"one safety copy exists next to the capture"
|
||||
);
|
||||
|
||||
let forgotten = lab.state.prune_orbit(lab.orbit).await.unwrap();
|
||||
assert!(
|
||||
!forgotten.contains(&capture),
|
||||
"the production capture survived: {forgotten:?}"
|
||||
);
|
||||
assert!(
|
||||
forgotten.is_empty(),
|
||||
"and the fresh safety copy is kept too: {forgotten:?}"
|
||||
);
|
||||
let vault = lab.state.vault.read().await;
|
||||
assert!(vault.get_snapshot(capture).unwrap().is_some());
|
||||
assert!(vault.get_snapshot(safety[0]).unwrap().is_some());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user