Skip to content

Commit f1b1178

Browse files
Fix Get Snapshots Request Cancellation with ignore_unavailable=true (#78004)
Short-circuit the failure method when cancelled just like in the fail fast case. Also, remove the special case handling that asserts but swallows exceptions in production for when ignoring unavailable to not swallow the task cancellation exception. closes #77980
1 parent 262fdc0 commit f1b1178

File tree

3 files changed

+5
-17
lines changed

3 files changed

+5
-17
lines changed

qa/smoke-test-http/src/test/java/org/elasticsearch/http/snapshots/RestGetSnapshotsCancellationIT.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public void testGetSnapshotsCancellation() throws Exception {
4141
repository.setBlockOnAnyFiles();
4242

4343
final Request request = new Request(HttpGet.METHOD_NAME, "/_snapshot/" + repoName + "/*");
44+
if (randomBoolean()) {
45+
request.addParameter("ignore_unavailable", "true");
46+
}
4447
final PlainActionFuture<Response> future = new PlainActionFuture<>();
4548
final Cancellable cancellable = getRestClient().performRequestAsync(request, wrapAsRestResponseListener(future));
4649

server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/TransportGetSnapshotsAction.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
package org.elasticsearch.action.admin.cluster.snapshots.get;
1010

11-
import org.apache.logging.log4j.LogManager;
12-
import org.apache.logging.log4j.Logger;
1311
import org.apache.lucene.util.CollectionUtil;
1412
import org.elasticsearch.ElasticsearchException;
1513
import org.elasticsearch.action.ActionListener;
@@ -67,8 +65,6 @@
6765
*/
6866
public class TransportGetSnapshotsAction extends TransportMasterNodeAction<GetSnapshotsRequest, GetSnapshotsResponse> {
6967

70-
private static final Logger logger = LogManager.getLogger(TransportGetSnapshotsAction.class);
71-
7268
private final RepositoriesService repositoriesService;
7369

7470
@Inject
@@ -443,18 +439,7 @@ private void snapshots(
443439
ignoreUnavailable == false,
444440
task::isCancelled,
445441
(context, snapshotInfo) -> snapshotInfos.add(snapshotInfo),
446-
ignoreUnavailable ? ActionListener.runAfter(new ActionListener<>() {
447-
@Override
448-
public void onResponse(Void unused) {
449-
logger.trace("done fetching snapshot infos [{}]", snapshotIdsToIterate);
450-
}
451-
452-
@Override
453-
public void onFailure(Exception e) {
454-
assert false : new AssertionError("listener should always complete successfully for ignoreUnavailable=true", e);
455-
logger.warn("failed to fetch snapshot info for some snapshots", e);
456-
}
457-
}, () -> allDoneListener.onResponse(null)) : allDoneListener
442+
allDoneListener
458443
)
459444
);
460445
}

server/src/main/java/org/elasticsearch/repositories/GetSnapshotInfoContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public void onResponse(SnapshotInfo snapshotInfo) {
125125
@Override
126126
public void onFailure(Exception e) {
127127
assert Repository.assertSnapshotMetaThread();
128-
if (abortOnFailure) {
128+
if (abortOnFailure || isCancelled()) {
129129
if (counter.fastForward()) {
130130
failDoneListener(e);
131131
}

0 commit comments

Comments
 (0)