@@ -1473,7 +1473,7 @@ protected void doRun() throws Exception {
1473
1473
try {
1474
1474
logger .debug ("[{}] triggering deletion of snapshot [{}]" , repository , snapshotId );
1475
1475
final PlainActionFuture <Void > future = PlainActionFuture .newFuture ();
1476
- deleteSnapshots (new DeleteSnapshotRequest (repository , snapshotId .getName ()), future );
1476
+ deleteSnapshotsByUuid (new DeleteSnapshotRequest (repository , snapshotId .getUUID ()), future );
1477
1477
future .actionGet ();
1478
1478
} finally {
1479
1479
removeSnapshotsToDelete (repository , snapshotId );
@@ -2354,18 +2354,47 @@ private void failSnapshotCompletionListeners(Snapshot snapshot, Exception e) {
2354
2354
}
2355
2355
2356
2356
/**
2357
- * Deletes snapshots from the repository. In-progress snapshots matched by the delete will be aborted before deleting them.
2357
+ * Deletes snapshots from the repository. In-progress snapshots matched by the delete will be aborted before deleting them. Snapshots
2358
+ * to delete are identified by their names.
2359
+ *
2360
+ * @param request delete snapshot request
2361
+ * @param listener listener
2362
+ */
2363
+ public void deleteSnapshotsByName (final DeleteSnapshotRequest request , final ActionListener <Void > listener ) {
2364
+ deleteSnapshots (SnapshotId ::getName , request , listener );
2365
+ }
2366
+
2367
+ /**
2368
+ * Deletes snapshots from the repository. In-progress snapshots matched by the delete will be aborted before deleting them. Snapshots
2369
+ * to delete are identified by their UUIDs.
2358
2370
*
2359
2371
* @param request delete snapshot request
2360
2372
* @param listener listener
2361
2373
*/
2362
- public void deleteSnapshots (final DeleteSnapshotRequest request , final ActionListener <Void > listener ) {
2374
+ private void deleteSnapshotsByUuid (final DeleteSnapshotRequest request , final ActionListener <Void > listener ) {
2375
+ deleteSnapshots (SnapshotId ::getUUID , request , listener );
2376
+ }
2377
+
2378
+ /**
2379
+ * Deletes snapshots from the repository. In-progress snapshots matched by the delete will be aborted before deleting them.
2380
+ * Snapshots to delete are identified by converting their {@link SnapshotId} to a {@link String} using the mapping function
2381
+ * {@code mapping}; the resulting string is then compared to the snapshots names/uuids/patterns to match against.
2382
+ *
2383
+ * @param mapping the mapping function used to match the {@link SnapshotId} against the given snapshotNamesOrUuids
2384
+ * @param request the {@link DeleteSnapshotRequest}
2385
+ * @param listener listener
2386
+ */
2387
+ private void deleteSnapshots (
2388
+ final Function <SnapshotId , String > mapping ,
2389
+ final DeleteSnapshotRequest request ,
2390
+ final ActionListener <Void > listener
2391
+ ) {
2363
2392
final String repositoryName = request .repository ();
2364
- final String [] snapshotNames = request .snapshots ();
2393
+ final String [] snapshotNamesOrUuids = request .snapshots ();
2365
2394
logger .info (
2366
2395
() -> new ParameterizedMessage (
2367
2396
"deleting snapshots [{}] from repository [{}]" ,
2368
- Strings .arrayToCommaDelimitedString (snapshotNames ),
2397
+ Strings .arrayToCommaDelimitedString (snapshotNamesOrUuids ),
2369
2398
repositoryName
2370
2399
)
2371
2400
);
@@ -2394,16 +2423,16 @@ public ClusterState execute(ClusterState currentState) {
2394
2423
final SnapshotsInProgress snapshotsInProgress = currentState .custom (SnapshotsInProgress .TYPE , SnapshotsInProgress .EMPTY );
2395
2424
for (SnapshotsInProgress .Entry entry : snapshotsInProgress .entries ()) {
2396
2425
final SnapshotId snapshotId = entry .snapshot ().getSnapshotId ();
2397
- if (entry .repository ().equals (repositoryName ) && Regex .simpleMatch (snapshotNames , snapshotId . getName ( ))) {
2426
+ if (entry .repository ().equals (repositoryName ) && Regex .simpleMatch (snapshotNamesOrUuids , mapping . apply ( snapshotId ))) {
2398
2427
snapshotIds .add (snapshotId );
2399
2428
}
2400
2429
}
2401
2430
2402
2431
// find snapshots to delete in repository data
2403
2432
final Map <String , SnapshotId > snapshotsIdsInRepository = repositoryData .getSnapshotIds ()
2404
2433
.stream ()
2405
- .collect (Collectors .toMap (SnapshotId :: getName , Function .identity ()));
2406
- for (String snapshotOrPattern : snapshotNames ) {
2434
+ .collect (Collectors .toMap (mapping , Function .identity ()));
2435
+ for (String snapshotOrPattern : snapshotNamesOrUuids ) {
2407
2436
if (Regex .isSimpleMatchPattern (snapshotOrPattern )) {
2408
2437
for (Map .Entry <String , SnapshotId > entry : snapshotsIdsInRepository .entrySet ()) {
2409
2438
if (Regex .simpleMatch (snapshotOrPattern , entry .getKey ())) {
@@ -2413,7 +2442,7 @@ public ClusterState execute(ClusterState currentState) {
2413
2442
} else {
2414
2443
final SnapshotId foundId = snapshotsIdsInRepository .get (snapshotOrPattern );
2415
2444
if (foundId == null ) {
2416
- if (snapshotIds .stream ().noneMatch (snapshotId -> snapshotId . getName () .equals (snapshotOrPattern ))) {
2445
+ if (snapshotIds .stream ().map ( mapping ). noneMatch (snapshot -> snapshot .equals (snapshotOrPattern ))) {
2417
2446
throw new SnapshotMissingException (repositoryName , snapshotOrPattern );
2418
2447
}
2419
2448
} else {
@@ -2570,7 +2599,7 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS
2570
2599
}
2571
2600
}
2572
2601
}
2573
- }, "delete snapshot [" + repository + "]" + Arrays .toString (snapshotNames ), listener ::onFailure );
2602
+ }, "delete snapshot [" + repository + "]" + Arrays .toString (snapshotNamesOrUuids ), listener ::onFailure );
2574
2603
}
2575
2604
2576
2605
/**
0 commit comments