Skip to content

Commit

Permalink
Turn StackTraceHandler into a static class
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmitterdorfer committed Jan 18, 2024
1 parent 0062799 commit b45b204
Showing 1 changed file with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import java.util.function.Function;

public class TransportGetStackTracesAction extends TransportAction<GetStackTracesRequest, GetStackTracesResponse> {
Expand Down Expand Up @@ -423,15 +424,13 @@ private void retrieveStackTraces(
}

StackTraceHandler handler = new StackTraceHandler(
submitTask,
clusterState,
client,
responseBuilder,
submitListener,
eventIds.size(),
// We need to expect a set of slices for each resolved index, plus one for the host metadata.
slicedEventIds.size() * indices.size() + (uniqueHostIDs.isEmpty() ? 0 : 1),
uniqueHostIDs.size()
uniqueHostIDs.size(),
(s, e) -> retrieveStackTraceDetails(submitTask, clusterState, client, responseBuilder, s, e, submitListener)
);
for (List<String> slice : slicedEventIds) {
mget(client, indices, slice, ActionListener.wrap(handler::onStackTraceResponse, submitListener::onFailure));
Expand Down Expand Up @@ -481,12 +480,9 @@ static <T> List<List<T>> sliced(List<T> c, int slices) {
return Collections.unmodifiableList(slicedList);
}

private class StackTraceHandler {
private static final class StackTraceHandler {
private final AtomicInteger expectedResponses;
private final int initialExpectedResponses;
private final Task submitTask;
private final ClusterState clusterState;
private final Client client;
private final GetStackTracesResponseBuilder responseBuilder;
private final ActionListener<GetStackTracesResponse> submitListener;
private final Map<String, StackTrace> stackTracePerId;
Expand All @@ -500,25 +496,23 @@ private class StackTraceHandler {
private final StopWatch hostsWatch = new StopWatch("retrieveHostMetadata");
private final Map<String, HostMetadata> hostMetadata;

private final BiConsumer<List<String>, List<String>> detailsHandler;

private StackTraceHandler(
Task submitTask,
ClusterState clusterState,
Client client,
GetStackTracesResponseBuilder responseBuilder,
ActionListener<GetStackTracesResponse> submitListener,
int stackTraceCount,
int expectedResponses,
int expectedHosts
int expectedHosts,
BiConsumer<List<String>, List<String>> detailsHandler
) {
this.submitTask = submitTask;
this.clusterState = clusterState;
this.stackTracePerId = new ConcurrentHashMap<>(stackTraceCount);
this.initialExpectedResponses = expectedResponses;
this.expectedResponses = new AtomicInteger(expectedResponses);
this.client = client;
this.responseBuilder = responseBuilder;
this.submitListener = submitListener;
this.hostMetadata = new HashMap<>(expectedHosts);
this.detailsHandler = detailsHandler;
}

public void onStackTraceResponse(MultiGetResponse multiGetItemResponses) {
Expand All @@ -540,7 +534,7 @@ public void onStackTraceResponse(MultiGetResponse multiGetItemResponses) {
if (stackTracePerId.putIfAbsent(id, stacktrace) == null) {
totalFrames.addAndGet(stacktrace.frameIds.size());
stackFrameIds.addAll(stacktrace.frameIds);
stacktrace.forNativeAndKernelFrames(e -> executableIds.add(e));
stacktrace.forNativeAndKernelFrames(executableIds::add);
}
}
}
Expand Down Expand Up @@ -621,7 +615,10 @@ public void mayFinish() {
TraceLogger.stop(null, "process stacktrace response finish");
TraceLogger.stop(null, "process stacktrace response");
TraceLogger.stop(null, "retrieveStackTraces");
retrieveStackTraceDetails(
detailsHandler.accept(new ArrayList<>(stackFrameIds),new ArrayList<>(executableIds));
/*
retrieveStackTraceDetails(new ArrayList<>(stackFrameIds),
new ArrayList<>(executableIds));
submitTask,
clusterState,
client,
Expand All @@ -630,6 +627,7 @@ public void mayFinish() {
new ArrayList<>(executableIds),
submitListener
);
*/
}
}
}
Expand Down

0 comments on commit b45b204

Please sign in to comment.