Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/86659.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 86659
summary: Use `TaskCancelledException` in TMNA
area: Task Management
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
import org.elasticsearch.node.NodeClosedException;
import org.elasticsearch.tasks.CancellableTask;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.tasks.TaskCancelledException;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.ConnectTransportException;
import org.elasticsearch.transport.RemoteTransportException;
import org.elasticsearch.transport.TransportException;
import org.elasticsearch.transport.TransportService;

import java.util.concurrent.CancellationException;
import java.util.function.Predicate;

/**
Expand Down Expand Up @@ -114,7 +114,7 @@ protected abstract void masterOperation(Task task, Request request, ClusterState
private void executeMasterOperation(Task task, Request request, ClusterState state, ActionListener<Response> listener)
throws Exception {
if (task instanceof CancellableTask && ((CancellableTask) task).isCancelled()) {
throw new CancellationException("Task was cancelled");
throw new TaskCancelledException("Task was cancelled");
}

masterOperation(task, request, state, listener);
Expand Down Expand Up @@ -168,7 +168,7 @@ class AsyncSingleAction {

protected void doStart(ClusterState clusterState) {
if (isTaskCancelled()) {
listener.onFailure(new CancellationException("Task was cancelled"));
listener.onFailure(new TaskCancelledException("Task was cancelled"));
return;
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.tasks.CancellableTask;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.tasks.TaskCancelledException;
import org.elasticsearch.tasks.TaskId;
import org.elasticsearch.tasks.TaskManager;
import org.elasticsearch.test.ESTestCase;
Expand All @@ -65,7 +66,6 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -594,7 +594,7 @@ protected ClusterBlockException checkBlock(Request request, ClusterState state)
}
setState(clusterService, newStateBuilder.build());
}
expectThrows(CancellationException.class, listener::actionGet);
expectThrows(TaskCancelledException.class, listener::actionGet);
}

public void testTaskCancellationOnceActionItIsDispatchedToMaster() throws Exception {
Expand All @@ -621,7 +621,7 @@ public void testTaskCancellationOnceActionItIsDispatchedToMaster() throws Except

releaseBlockedThreads.run();

expectThrows(CancellationException.class, listener::actionGet);
expectThrows(TaskCancelledException.class, listener::actionGet);
}

public void testGlobalBlocksAreCheckedAfterIndexNotFoundException() throws Exception {
Expand Down