From 03e8734b04d841e31724b10cf0d9c41801699411 Mon Sep 17 00:00:00 2001 From: Andrey Ershov Date: Tue, 25 Jun 2019 15:44:48 +0300 Subject: [PATCH] Fix GET /_snapshot/_all/_all if there are no repos (#43558) 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 --- .../snapshots/get/TransportGetSnapshotsAction.java | 5 +++++ .../snapshots/SharedClusterSnapshotRestoreIT.java | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/TransportGetSnapshotsAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/TransportGetSnapshotsAction.java index 246b9c8fe132c..4d2dcf92d70ec 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/TransportGetSnapshotsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/TransportGetSnapshotsAction.java @@ -112,6 +112,11 @@ protected void masterOperation(final GetSnapshotsRequest request, final ClusterS private void getMultipleReposSnapshotInfo(List repos, String[] snapshots, boolean ignoreUnavailable, boolean verbose, ActionListener 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 groupedActionListener = new GroupedActionListener<>( ActionListener.map(listener, responses -> { diff --git a/server/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java b/server/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java index d5d52c150e457..4d475fc7b0b1b 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java +++ b/server/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java @@ -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();