Skip to content

Commit

Permalink
[Profiling] Use default task cancellation check
Browse files Browse the repository at this point in the history
With this commit we remove our custom implementation of whether a
task has been cancelled and instead use the standard implementation that
is already provided by the task API.
  • Loading branch information
danielmitterdorfer committed Apr 3, 2024
1 parent 573c032 commit 6610ac3
Showing 1 changed file with 2 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.tasks.CancellableTask;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.tasks.TaskCancelledException;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.xcontent.ObjectPath;
Expand Down Expand Up @@ -155,22 +154,6 @@ protected void doExecute(Task submitTask, GetStackTracesRequest request, ActionL
}
}

/**
* Checks whether a task has been cancelled and notifies the provided listener if required.
* @param task The task to check. May be a cancelable task.
* @param listener Listener to notify.
* @return <code>true</code> iff the task has been cancelled. Callers must terminate as early as possible.
*/
private boolean mayNotifyOfCancellation(Task task, ActionListener<GetStackTracesResponse> listener) {
if (task instanceof CancellableTask && ((CancellableTask) task).isCancelled()) {
log.info("{} got cancelled.", task);
listener.onFailure(new TaskCancelledException("get stacktraces task cancelled"));
return true;
} else {
return false;
}
}

private void searchProfilingEvents(
Task submitTask,
Client client,
Expand Down Expand Up @@ -447,7 +430,7 @@ private void retrieveStackTraces(
GetStackTracesResponseBuilder responseBuilder,
ActionListener<GetStackTracesResponse> submitListener
) {
if (mayNotifyOfCancellation(submitTask, submitListener)) {
if (submitTask instanceof CancellableTask c && c.notifyIfCancelled(submitListener)) {
return;
}
List<String> eventIds = new ArrayList<>(responseBuilder.getStackTraceEvents().keySet());
Expand Down Expand Up @@ -670,7 +653,7 @@ private void retrieveStackTraceDetails(
List<String> executableIds,
ActionListener<GetStackTracesResponse> submitListener
) {
if (mayNotifyOfCancellation(submitTask, submitListener)) {
if (submitTask instanceof CancellableTask c && c.notifyIfCancelled(submitListener)) {
return;
}
List<Index> stackFrameIndices = resolver.resolve(
Expand Down

0 comments on commit 6610ac3

Please sign in to comment.