Skip to content

Commit

Permalink
[Profiling] Use CancellableTask internally
Browse files Browse the repository at this point in the history
With this commit we eagerly cast the task provided to our central
transport action to a CancellableTask so we can simplify cancellation
checks while the action is being executed.

Relates elastic#107037
  • Loading branch information
danielmitterdorfer committed Apr 5, 2024
1 parent ab19b60 commit 9bf6088
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ public TransportGetStackTracesAction(
}

@Override
protected void doExecute(Task submitTask, GetStackTracesRequest request, ActionListener<GetStackTracesResponse> submitListener) {
protected void doExecute(Task task, GetStackTracesRequest request, ActionListener<GetStackTracesResponse> submitListener) {
licenseChecker.requireSupportedLicense();
assert task instanceof CancellableTask;
final CancellableTask submitTask = (CancellableTask) task;
GetStackTracesResponseBuilder responseBuilder = new GetStackTracesResponseBuilder(request);
Client client = new ParentTaskAssigningClient(this.nodeClient, transportService.getLocalNode(), submitTask);
if (request.isUserProvidedIndices()) {
Expand All @@ -161,7 +163,7 @@ protected void doExecute(Task submitTask, GetStackTracesRequest request, ActionL
}

private void searchProfilingEvents(
Task submitTask,
CancellableTask submitTask,
Client client,
GetStackTracesRequest request,
ActionListener<GetStackTracesResponse> submitListener,
Expand Down Expand Up @@ -201,7 +203,7 @@ private void searchProfilingEvents(
}

private void searchGenericEvents(
Task submitTask,
CancellableTask submitTask,
Client client,
GetStackTracesRequest request,
ActionListener<GetStackTracesResponse> submitListener,
Expand Down Expand Up @@ -240,7 +242,7 @@ private void searchGenericEvents(
}

private void searchGenericEventGroupedByStackTrace(
Task submitTask,
CancellableTask submitTask,
Client client,
GetStackTracesRequest request,
ActionListener<GetStackTracesResponse> submitListener,
Expand Down Expand Up @@ -320,7 +322,7 @@ private void searchGenericEventGroupedByStackTrace(
}

private void searchEventGroupedByStackTrace(
Task submitTask,
CancellableTask submitTask,
Client client,
GetStackTracesRequest request,
ActionListener<GetStackTracesResponse> submitListener,
Expand Down Expand Up @@ -432,7 +434,7 @@ The same stacktraces may come from different hosts (eventually from different da
}

private ActionListener<SearchResponse> handleEventsGroupedByStackTrace(
Task submitTask,
CancellableTask submitTask,
Client client,
GetStackTracesResponseBuilder responseBuilder,
ActionListener<GetStackTracesResponse> submitListener,
Expand Down Expand Up @@ -471,12 +473,12 @@ private static long getAggValueAsLong(SearchResponse searchResponse, String fiel
}

private void retrieveStackTraces(
Task submitTask,
CancellableTask submitTask,
Client client,
GetStackTracesResponseBuilder responseBuilder,
ActionListener<GetStackTracesResponse> submitListener
) {
if (submitTask instanceof CancellableTask c && c.notifyIfCancelled(submitListener)) {
if (submitTask.notifyIfCancelled(submitListener)) {
return;
}
List<String> eventIds = new ArrayList<>(responseBuilder.getStackTraceEvents().keySet());
Expand Down Expand Up @@ -554,7 +556,7 @@ static <T> List<List<T>> sliced(List<T> c, int slices) {

private class StackTraceHandler {
private final AtomicInteger expectedResponses;
private final Task submitTask;
private final CancellableTask submitTask;
private final ClusterState clusterState;
private final Client client;
private final GetStackTracesResponseBuilder responseBuilder;
Expand All @@ -568,7 +570,7 @@ private class StackTraceHandler {
private final Map<String, HostMetadata> hostMetadata;

private StackTraceHandler(
Task submitTask,
CancellableTask submitTask,
ClusterState clusterState,
Client client,
GetStackTracesResponseBuilder responseBuilder,
Expand Down Expand Up @@ -691,15 +693,15 @@ public void mayFinish() {
}

private void retrieveStackTraceDetails(
Task submitTask,
CancellableTask submitTask,
ClusterState clusterState,
Client client,
GetStackTracesResponseBuilder responseBuilder,
List<String> stackFrameIds,
List<String> executableIds,
ActionListener<GetStackTracesResponse> submitListener
) {
if (submitTask instanceof CancellableTask c && c.notifyIfCancelled(submitListener)) {
if (submitTask.notifyIfCancelled(submitListener)) {
return;
}
List<Index> stackFrameIndices = resolver.resolve(
Expand Down

0 comments on commit 9bf6088

Please sign in to comment.