Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/140200.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 140200
summary: Use `IllegalArgumentException` over `RepositoryException` for readonly-repository
checks
area: Snapshot/Restore
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ public void testReadonlyRepository() throws Exception {
logger.info("--> try deleting snapshot");
assertRequestBuilderThrows(
client.admin().cluster().prepareDeleteSnapshot(TEST_REQUEST_TIMEOUT, "readonly-repo", "test-snap"),
RepositoryException.class,
IllegalArgumentException.class,
"repository is readonly"
);

Expand All @@ -1109,7 +1109,7 @@ public void testReadonlyRepository() throws Exception {
.prepareCreateSnapshot(TEST_REQUEST_TIMEOUT, "readonly-repo", "test-snap-2")
.setWaitForCompletion(true)
.setIndices("test-idx"),
RepositoryException.class,
IllegalArgumentException.class,
"cannot create snapshot in a readonly repository"
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2850,7 +2850,7 @@ public ClusterState execute(ClusterState currentState) {
// Last resort check: we shouldn't have been able to mark the repository as readonly while the operation that led to
// this writeIndexGen() call was in progress, and conversely shouldn't have started any such operation if the repo
// was already readonly, but these invariants are not obviously true and it is disastrous to proceed here.
throw new RepositoryException(meta.name(), "repository is readonly, cannot update root blob");
throw new IllegalArgumentException("[" + meta.name() + "] repository is readonly, cannot update root blob");
}

final long genInState = meta.generation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ public void createSnapshot(final ProjectId projectId, final CreateSnapshotReques
final SnapshotId snapshotId = new SnapshotId(snapshotName, request.uuid());
Repository repository = repositoriesService.repository(projectId, request.repository());
if (repository.isReadOnly()) {
listener.onFailure(new RepositoryException(repository.getMetadata().name(), "cannot create snapshot in a readonly repository"));
listener.onFailure(
new IllegalArgumentException("[" + repository.getMetadata().name() + "] cannot create snapshot in a readonly repository")
);
return;
}
submitCreateSnapshotRequest(
Expand Down Expand Up @@ -3116,7 +3118,7 @@ public ClusterState execute(BatchExecutionContext<SnapshotTask> batchExecutionCo
final var projectMetadata = state.metadata().getProject(task.snapshot.getProjectId());
final var repoMeta = RepositoriesMetadata.get(projectMetadata).repository(task.snapshot.getRepository());
if (RepositoriesService.isReadOnly(repoMeta.settings())) {
taskContext.onFailure(new RepositoryException(repoMeta.name(), "repository is readonly"));
taskContext.onFailure(new IllegalArgumentException("[" + repoMeta.name() + "] repository is readonly"));
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import org.elasticsearch.repositories.RepositoriesService;
import org.elasticsearch.repositories.Repository;
import org.elasticsearch.repositories.RepositoryData;
import org.elasticsearch.repositories.RepositoryException;
import org.elasticsearch.repositories.RepositoryMissingException;
import org.elasticsearch.repositories.RepositoryShardId;
import org.elasticsearch.repositories.ShardGeneration;
Expand Down Expand Up @@ -126,7 +125,7 @@ public static void ensureNoCleanupInProgress(
public static void ensureNotReadOnly(final ProjectMetadata projectMetadata, final String repositoryName) {
final var repositoryMetadata = RepositoriesMetadata.get(projectMetadata).repository(repositoryName);
if (RepositoriesService.isReadOnly(repositoryMetadata.settings())) {
throw new RepositoryException(repositoryMetadata.name(), "repository is readonly");
throw new IllegalArgumentException("[" + repositoryMetadata.name() + "] repository is readonly");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public void testIndexGenerationalFiles() throws Exception {
containsString("[test-repo] Failed to execute cluster state update [set pending repository generation")
);
assertThat(
asInstanceOf(RepositoryException.class, e.getCause()).getMessage(),
asInstanceOf(IllegalArgumentException.class, e.getCause()).getMessage(),
containsString("[test-repo] repository is readonly, cannot update root blob")
);
l.onResponse(null);
Expand Down