Skip to content

Commit

Permalink
Improve cancellation in repo analysis (elastic#101213)
Browse files Browse the repository at this point in the history
Today we rely on an `isRunning` check to check for task cancellation,
but since elastic#82685 we can actively record the failure arising from the
cancellation using a `CancellationListener`.

Closes elastic#101197
  • Loading branch information
DaveCTurner committed Oct 24, 2023
1 parent 482cf3b commit b714549
Showing 1 changed file with 4 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -437,22 +437,10 @@ private void fail(Exception e) {
}

/**
* 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
* cause of failure.
* Check that we haven't already failed (including cancellation and timing out).
*/
private boolean isRunning() {
if (failure.get() != null) {
return false;
}

if (task.isCancelled()) {
setFirstFailure(new RepositoryVerificationException(request.repositoryName, "verification cancelled"));
// if this CAS failed then we're failing for some other reason, nbd; also if the task is cancelled then its descendants are
// also cancelled, so no further action is needed either way.
return false;
}

return true;
return failure.get() == null;
}

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

task.addListener(() -> setFirstFailure(new RepositoryVerificationException(request.repositoryName, "analysis cancelled")));

final Random random = new Random(request.getSeed());
final List<DiscoveryNode> nodes = getSnapshotNodes(discoveryNodes);

Expand Down

0 comments on commit b714549

Please sign in to comment.