diff --git a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java index 0a0baccb1ad..3c513165234 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java @@ -1604,10 +1604,11 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas logger.info("--> execution was blocked on node [{}], trying to delete repository", blockedNode); try { - client.admin().cluster().prepareDeleteRepository("test-repo").execute().get(); + client.admin().cluster().prepareDeleteRepository(randomFrom("test-repo", "test-*", "*")).execute().actionGet(); fail("shouldn't be able to delete in-use repository"); } catch (Exception ex) { logger.info("--> in-use repository deletion failed"); + assertThat(ex.getMessage(), containsString("trying to modify or unregister repository that is currently used")); } logger.info("--> trying to move repository to another location"); diff --git a/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java b/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java index 3ee39f53f42..a4940b1d2a6 100644 --- a/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java +++ b/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java @@ -205,7 +205,6 @@ public class RepositoriesService extends AbstractLifecycleComponent implements C @Override public ClusterState execute(ClusterState currentState) { - ensureRepositoryNotInUse(currentState, request.name()); Metadata metadata = currentState.metadata(); Metadata.Builder mdBuilder = Metadata.builder(currentState.metadata()); RepositoriesMetadata repositories = metadata.custom(RepositoriesMetadata.TYPE); @@ -214,6 +213,7 @@ public class RepositoriesService extends AbstractLifecycleComponent implements C boolean changed = false; for (RepositoryMetadata repositoryMetadata : repositories.repositories()) { if (Regex.simpleMatch(request.name(), repositoryMetadata.name())) { + ensureRepositoryNotInUse(currentState, repositoryMetadata.name()); logger.info("delete repository [{}]", repositoryMetadata.name()); changed = true; } else { @@ -465,7 +465,7 @@ public class RepositoriesService extends AbstractLifecycleComponent implements C private static void ensureRepositoryNotInUse(ClusterState clusterState, String repository) { if (isRepositoryInUse(clusterState, repository)) { - throw new IllegalStateException("trying to modify or unregister repository that is currently used "); + throw new IllegalStateException("trying to modify or unregister repository that is currently used"); } }