@@ -1473,7 +1473,7 @@ protected void doRun() throws Exception {
14731473 try {
14741474 logger .debug ("[{}] triggering deletion of snapshot [{}]" , repository , snapshotId );
14751475 final PlainActionFuture <Void > future = PlainActionFuture .newFuture ();
1476- deleteSnapshots (new DeleteSnapshotRequest (repository , snapshotId .getName ()), future );
1476+ deleteSnapshotsByUuid (new DeleteSnapshotRequest (repository , snapshotId .getUUID ()), future );
14771477 future .actionGet ();
14781478 } finally {
14791479 removeSnapshotsToDelete (repository , snapshotId );
@@ -2354,18 +2354,47 @@ private void failSnapshotCompletionListeners(Snapshot snapshot, Exception e) {
23542354 }
23552355
23562356 /**
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.
23582370 *
23592371 * @param request delete snapshot request
23602372 * @param listener listener
23612373 */
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+ ) {
23632392 final String repositoryName = request .repository ();
2364- final String [] snapshotNames = request .snapshots ();
2393+ final String [] snapshotNamesOrUuids = request .snapshots ();
23652394 logger .info (
23662395 () -> new ParameterizedMessage (
23672396 "deleting snapshots [{}] from repository [{}]" ,
2368- Strings .arrayToCommaDelimitedString (snapshotNames ),
2397+ Strings .arrayToCommaDelimitedString (snapshotNamesOrUuids ),
23692398 repositoryName
23702399 )
23712400 );
@@ -2394,16 +2423,16 @@ public ClusterState execute(ClusterState currentState) {
23942423 final SnapshotsInProgress snapshotsInProgress = currentState .custom (SnapshotsInProgress .TYPE , SnapshotsInProgress .EMPTY );
23952424 for (SnapshotsInProgress .Entry entry : snapshotsInProgress .entries ()) {
23962425 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 ))) {
23982427 snapshotIds .add (snapshotId );
23992428 }
24002429 }
24012430
24022431 // find snapshots to delete in repository data
24032432 final Map <String , SnapshotId > snapshotsIdsInRepository = repositoryData .getSnapshotIds ()
24042433 .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 ) {
24072436 if (Regex .isSimpleMatchPattern (snapshotOrPattern )) {
24082437 for (Map .Entry <String , SnapshotId > entry : snapshotsIdsInRepository .entrySet ()) {
24092438 if (Regex .simpleMatch (snapshotOrPattern , entry .getKey ())) {
@@ -2413,7 +2442,7 @@ public ClusterState execute(ClusterState currentState) {
24132442 } else {
24142443 final SnapshotId foundId = snapshotsIdsInRepository .get (snapshotOrPattern );
24152444 if (foundId == null ) {
2416- if (snapshotIds .stream ().noneMatch (snapshotId -> snapshotId . getName () .equals (snapshotOrPattern ))) {
2445+ if (snapshotIds .stream ().map ( mapping ). noneMatch (snapshot -> snapshot .equals (snapshotOrPattern ))) {
24172446 throw new SnapshotMissingException (repositoryName , snapshotOrPattern );
24182447 }
24192448 } else {
@@ -2570,7 +2599,7 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS
25702599 }
25712600 }
25722601 }
2573- }, "delete snapshot [" + repository + "]" + Arrays .toString (snapshotNames ), listener ::onFailure );
2602+ }, "delete snapshot [" + repository + "]" + Arrays .toString (snapshotNamesOrUuids ), listener ::onFailure );
25742603 }
25752604
25762605 /**
0 commit comments