Ensure repo not in use for wildcard repo deletes (#60947)

Repositories can't be unregistered when they are actively being used for snapshots or restores. Wildcard repository
deletes could silently bypass the "repo in use" checks however, which is now fixed.
This commit is contained in:
Yannick Welsch 2020-08-11 12:58:01 +02:00
parent c80d36706b
commit af519be9cb
2 changed files with 4 additions and 3 deletions

View File

@ -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");

View File

@ -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");
}
}