Skip to content

Commit 0a9451d

Browse files
committed
Snapshot invocations WIP
1 parent 3ee3331 commit 0a9451d

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

x-pack/plugin/slm/src/main/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTask.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -496,14 +496,6 @@ public ClusterState execute(ClusterState currentState) throws Exception {
496496
final SnapshotLifecyclePolicyMetadata.Builder newPolicyMetadata = SnapshotLifecyclePolicyMetadata.builder(policyMetadata);
497497
SnapshotLifecycleStats newStats = snapMeta.getStats();
498498

499-
if (registeredSnapshots.contains(snapshotId) == false) {
500-
logger.warn(
501-
"Snapshot [{}] not found in registered set after snapshot completion. This means snapshot was"
502-
+ " recorded as a failure by another snapshot's cleanup run.",
503-
snapshotId.getName()
504-
);
505-
}
506-
507499
final Set<SnapshotId> runningSnapshots = currentlyRunningSnapshots(currentState);
508500
final List<PolicySnapshot> newRegistered = new ArrayList<>();
509501

@@ -553,7 +545,13 @@ public ClusterState execute(ClusterState currentState) throws Exception {
553545
}
554546

555547
// Add stats from the just completed snapshot execution
556-
if (exception.isPresent()) {
548+
if (registeredSnapshots.contains(snapshotId) == false) {
549+
logger.warn(
550+
"Snapshot [{}] not found in registered set after snapshot completion. This means snapshot was"
551+
+ " recorded as a failure by another snapshot's cleanup run.",
552+
snapshotId.getName()
553+
);
554+
} else if (exception.isPresent()) {
557555
newStats = newStats.withFailedIncremented(policyName);
558556
newPolicyMetadata.setLastFailure(
559557
new SnapshotInvocationRecord(

x-pack/plugin/slm/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTaskTests.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,13 @@ public void testCleanUpRegisteredInitiatedBySuccess() throws Exception {
469469
var definedSlmPolicies = List.of(policyId);
470470
var registeredSnapshots = Map.of(
471471
policyId,
472-
List.of(stillRunning, inferredFailureSnapshot, snapshotInfoSuccess.snapshotId(), snapshotInfoFailure.snapshotId())
472+
List.of(
473+
stillRunning,
474+
inferredFailureSnapshot,
475+
snapshotInfoSuccess.snapshotId(),
476+
snapshotInfoFailure.snapshotId(),
477+
initiatingSnapshot
478+
)
473479
);
474480
var inProgress = Map.of(policyId, List.of(stillRunning));
475481
ClusterState clusterState = buildClusterState(projectId, definedSlmPolicies, registeredSnapshots, inProgress);
@@ -528,7 +534,8 @@ public void testCleanUpRegisteredInitiatedByFailure() throws Exception {
528534
inferredFailureSnapshot,
529535
snapshotInfoSuccess.snapshotId(),
530536
snapshotInfoFailure1.snapshotId(),
531-
snapshotInfoFailure2.snapshotId()
537+
snapshotInfoFailure2.snapshotId(),
538+
initiatingSnapshot
532539
)
533540
);
534541
var inProgress = Map.of(policyId, List.of(stillRunning));

0 commit comments

Comments
 (0)