fix(ilm): validate persisted transition jobs

Refs #1479

Co-Authored-By: heihutu <heihutu@gmail.com>
This commit is contained in:
houseme
2026-07-25 18:54:28 +08:00
parent 752b0b4440
commit 484e6a07dc
2 changed files with 129 additions and 36 deletions
@@ -2446,6 +2446,7 @@ pub struct ManualTransitionRunOptions {
}
#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ManualTransitionRunReport {
pub bucket: String,
pub prefix: String,
@@ -2480,6 +2481,19 @@ pub struct ManualTransitionRunExecution {
pub cancelled: bool,
}
impl ManualTransitionRunExecution {
fn completed(report: ManualTransitionRunReport) -> Self {
Self {
report,
cancelled: false,
}
}
fn cancelled(report: ManualTransitionRunReport) -> Self {
Self { report, cancelled: true }
}
}
impl ManualTransitionRunReport {
fn new(bucket: &str, options: &ManualTransitionRunOptions) -> Self {
Self {
@@ -2543,10 +2557,7 @@ pub async fn enqueue_transition_for_existing_objects_scoped_with_cancel(
let mut report = ManualTransitionRunReport::new(bucket, &options);
let Some(lc) = runtime_sources::bucket_lifecycle_config(bucket).await else {
return Ok(ManualTransitionRunExecution {
report,
cancelled: false,
});
return Ok(ManualTransitionRunExecution::completed(report));
};
report.lifecycle_config_found = true;
let mut marker = options.marker.clone();
@@ -2558,7 +2569,7 @@ pub async fn enqueue_transition_for_existing_objects_scoped_with_cancel(
loop {
if manual_transition_cancelled(cancel_token.as_ref()) {
return Ok(ManualTransitionRunExecution { report, cancelled: true });
return Ok(ManualTransitionRunExecution::cancelled(report));
}
let page = api
@@ -2570,26 +2581,20 @@ pub async fn enqueue_transition_for_existing_objects_scoped_with_cancel(
if manual_transition_cancelled(cancel_token.as_ref()) {
report.next_marker.clone_from(&previous_marker);
report.next_version_idmarker.clone_from(&previous_version_marker);
return Ok(ManualTransitionRunExecution { report, cancelled: true });
return Ok(ManualTransitionRunExecution::cancelled(report));
}
if manual_transition_duration_elapsed(deadline) {
report.truncated_by_duration = true;
report.next_marker.clone_from(&previous_marker);
report.next_version_idmarker.clone_from(&previous_version_marker);
return Ok(ManualTransitionRunExecution {
report,
cancelled: false,
});
return Ok(ManualTransitionRunExecution::completed(report));
}
report.scanned = report.scanned.saturating_add(1);
enqueue_transition_with_lifecycle_report(object, &lc, &src, &options, &mut report).await;
if report.has_partial_enqueue() {
report.next_marker.clone_from(&previous_marker);
report.next_version_idmarker.clone_from(&previous_version_marker);
return Ok(ManualTransitionRunExecution {
report,
cancelled: false,
});
return Ok(ManualTransitionRunExecution::completed(report));
}
if options.max_objects.is_some_and(|max_objects| report.scanned >= max_objects) {
if manual_transition_has_more_after_limit(index, page.objects.len(), page.is_truncated) {
@@ -2597,29 +2602,20 @@ pub async fn enqueue_transition_for_existing_objects_scoped_with_cancel(
report.next_marker = Some(object.name.clone());
report.next_version_idmarker = Some(manual_transition_version_marker(object));
}
return Ok(ManualTransitionRunExecution {
report,
cancelled: false,
});
return Ok(ManualTransitionRunExecution::completed(report));
}
previous_marker = Some(object.name.clone());
previous_version_marker = Some(manual_transition_version_marker(object));
}
if !page.is_truncated {
return Ok(ManualTransitionRunExecution {
report,
cancelled: false,
});
return Ok(ManualTransitionRunExecution::completed(report));
}
if manual_transition_duration_elapsed(deadline) {
report.truncated_by_duration = true;
report.next_marker.clone_from(&previous_marker);
report.next_version_idmarker.clone_from(&previous_version_marker);
return Ok(ManualTransitionRunExecution {
report,
cancelled: false,
});
return Ok(ManualTransitionRunExecution::completed(report));
}
marker = page.next_marker;