Skip to content

Commit b714549

Browse files
authored
Improve cancellation in repo analysis (#101213)
Today we rely on an `isRunning` check to check for task cancellation, but since #82685 we can actively record the failure arising from the cancellation using a `CancellationListener`. Closes #101197
1 parent 482cf3b commit b714549

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

x-pack/plugin/snapshot-repo-test-kit/src/main/java/org/elasticsearch/repositories/blobstore/testkit/RepositoryAnalyzeAction.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -437,22 +437,10 @@ private void fail(Exception e) {
437437
}
438438

439439
/**
440-
* Check that we haven't already failed or been cancelled or timed out; if newly cancelled or timed out then record this as the root
441-
* cause of failure.
440+
* Check that we haven't already failed (including cancellation and timing out).
442441
*/
443442
private boolean isRunning() {
444-
if (failure.get() != null) {
445-
return false;
446-
}
447-
448-
if (task.isCancelled()) {
449-
setFirstFailure(new RepositoryVerificationException(request.repositoryName, "verification cancelled"));
450-
// if this CAS failed then we're failing for some other reason, nbd; also if the task is cancelled then its descendants are
451-
// also cancelled, so no further action is needed either way.
452-
return false;
453-
}
454-
455-
return true;
443+
return failure.get() == null;
456444
}
457445

458446
private class CheckForCancelListener implements ActionListener<Void> {
@@ -485,6 +473,8 @@ public void run() {
485473
cancellationListener.addTimeout(request.getTimeout(), repository.threadPool(), EsExecutors.DIRECT_EXECUTOR_SERVICE);
486474
cancellationListener.addListener(new CheckForCancelListener());
487475

476+
task.addListener(() -> setFirstFailure(new RepositoryVerificationException(request.repositoryName, "analysis cancelled")));
477+
488478
final Random random = new Random(request.getSeed());
489479
final List<DiscoveryNode> nodes = getSnapshotNodes(discoveryNodes);
490480

0 commit comments

Comments
 (0)