Skip to content

Commit

Permalink
Wrap async ql task execution in new tracing context (#89029)
Browse files Browse the repository at this point in the history
Part of #84369. Split out from #88443. This PR wraps parts logic in
`AsyncTaskManagementService` in a new tracing context. This is
necessary so that a tracing implementation can use the thread context
to propagate tracing headers, but without the code attempting to set the
same key twice in the thread context, which is illegal.
  • Loading branch information
pugnascotia authored Aug 2, 2022
1 parent d01dd39 commit 241f1bc
Showing 1 changed file with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,22 @@ public void asyncExecute(
ActionListener<Response> listener
) {
String nodeId = clusterService.localNode().getId();
@SuppressWarnings("unchecked")
T searchTask = (T) taskManager.register("transport", action + "[a]", new AsyncRequestWrapper(request, nodeId));
boolean operationStarted = false;
try {
operation.execute(
request,
searchTask,
wrapStoringListener(searchTask, waitForCompletionTimeout, keepAlive, keepOnCompletion, listener)
);
operationStarted = true;
} finally {
// If we didn't start operation for any reason, we need to clean up the task that we have created
if (operationStarted == false) {
taskManager.unregister(searchTask);
try (var ignored = threadPool.getThreadContext().newTraceContext()) {
@SuppressWarnings("unchecked")
T searchTask = (T) taskManager.register("transport", action + "[a]", new AsyncRequestWrapper(request, nodeId));
boolean operationStarted = false;
try {
operation.execute(
request,
searchTask,
wrapStoringListener(searchTask, waitForCompletionTimeout, keepAlive, keepOnCompletion, listener)
);
operationStarted = true;
} finally {
// If we didn't start operation for any reason, we need to clean up the task that we have created
if (operationStarted == false) {
taskManager.unregister(searchTask);
}
}
}
}
Expand Down

0 comments on commit 241f1bc

Please sign in to comment.