Skip to content

Commit

Permalink
Fix GET /_snapshot/_all/_all if there are no repos (#43558)
Browse files Browse the repository at this point in the history
When there are no repositories, a request to GET /_snapshot/_all/_all
returns a 504 timeout error.
This happens because try to create GroupedActionListener with the
size of zero, which leads to an exception.
This commit short-circuits if there are no repos and adds a test to
verify the fix.

Closes #43547
  • Loading branch information
andrershov authored Jun 25, 2019
1 parent 4f6ec95 commit 03e8734
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ protected void masterOperation(final GetSnapshotsRequest request, final ClusterS

private void getMultipleReposSnapshotInfo(List<RepositoryMetaData> repos, String[] snapshots, boolean ignoreUnavailable,
boolean verbose, ActionListener<GetSnapshotsResponse> listener) {
// short-circuit if there are no repos, because we can not create GroupedActionListener of size 0
if (repos.isEmpty()) {
listener.onResponse(new GetSnapshotsResponse(Collections.emptyList()));
return;
}
final GroupedActionListener<GetSnapshotsResponse.Response> groupedActionListener =
new GroupedActionListener<>(
ActionListener.map(listener, responses -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,18 @@ public void testDeleteSnapshot() throws Exception {
assertThat(numberOfFiles(repo), equalTo(numberOfFiles[0] + 2));
}

public void testGetSnapshotsNoRepos() {
ensureGreen();
GetSnapshotsResponse getSnapshotsResponse = client().admin().cluster()
.prepareGetSnapshots(new String[]{"_all"})
.setSnapshots(randomFrom("_all", "*"))
.get();

assertTrue(getSnapshotsResponse.getRepositories().isEmpty());
assertTrue(getSnapshotsResponse.getFailedResponses().isEmpty());
assertTrue(getSnapshotsResponse.getSuccessfulResponses().isEmpty());
}

public void testGetSnapshotsMultipleRepos() {
final Client client = client();

Expand Down

0 comments on commit 03e8734

Please sign in to comment.