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
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public static void preProcess(SearchContext context) {
}
Collector collector = context.getProfilers() == null
? BucketCollector.NO_OP_COLLECTOR
: new InternalProfileCollector(BucketCollector.NO_OP_COLLECTOR, CollectorResult.REASON_AGGREGATION, List.of());
: new InternalProfileCollector(BucketCollector.NO_OP_COLLECTOR, CollectorResult.REASON_AGGREGATION);
context.registerAggsCollector(collector);
} else {
Collector collector = context.getProfilers() == null
? bucketCollector.asCollector()
: new InternalProfileCollector(bucketCollector.asCollector(), CollectorResult.REASON_AGGREGATION, List.of());
: new InternalProfileCollector(bucketCollector.asCollector(), CollectorResult.REASON_AGGREGATION);
context.registerAggsCollector(collector);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,7 @@ private void executeKnnVectorQuery(SearchContext context) throws IOException {
TopScoreDocCollector topScoreDocCollector = TopScoreDocCollector.create(knnSearch.get(i).k(), Integer.MAX_VALUE);
Collector collector = topScoreDocCollector;
if (context.getProfilers() != null) {
InternalProfileCollector ipc = new InternalProfileCollector(
topScoreDocCollector,
CollectorResult.REASON_SEARCH_TOP_HITS,
List.of()
);
InternalProfileCollector ipc = new InternalProfileCollector(topScoreDocCollector, CollectorResult.REASON_SEARCH_TOP_HITS);
QueryProfiler knnProfiler = context.getProfilers().getDfsProfiler().addQueryProfiler(ipc);
collector = ipc;
// Set the current searcher profiler to gather query profiling information for gathering top K docs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* This class wraps a Lucene Collector and times the execution of:
Expand All @@ -42,14 +43,18 @@ public class InternalProfileCollector implements Collector {
private final ProfileCollector collector;

/**
* A list of "embedded" children collectors
* An array of "embedded" children collectors
*/
private final List<InternalProfileCollector> children;
private final InternalProfileCollector[] children;

public InternalProfileCollector(Collector collector, String reason, List<InternalProfileCollector> children) {
public InternalProfileCollector(Collector collector, String reason, InternalProfileCollector... children) {
this.collector = new ProfileCollector(collector);
this.reason = reason;
this.collectorName = deriveCollectorName(collector);
Objects.requireNonNull(children, "children collectors cannot be null");
for (InternalProfileCollector child : children) {
Objects.requireNonNull(child, "child collector cannot be null");
}
this.children = children;
}

Expand Down Expand Up @@ -115,7 +120,7 @@ public CollectorResult getCollectorTree() {
}

private static CollectorResult doGetCollectorTree(InternalProfileCollector collector) {
List<CollectorResult> childResults = new ArrayList<>(collector.children.size());
List<CollectorResult> childResults = new ArrayList<>(collector.children.length);
for (InternalProfileCollector child : collector.children) {
CollectorResult result = doGetCollectorTree(child);
childResults.add(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static org.elasticsearch.search.profile.query.CollectorResult.REASON_SEARCH_MIN_SCORE;
Expand Down Expand Up @@ -57,7 +56,10 @@ public ScoreMode scoreMode() {
*/
protected InternalProfileCollector createWithProfiler(InternalProfileCollector in) throws IOException {
final Collector collector = create(in);
return new InternalProfileCollector(collector, profilerName, in != null ? Collections.singletonList(in) : Collections.emptyList());
if (in == null) {
return new InternalProfileCollector(collector, profilerName);
}
return new InternalProfileCollector(collector, profilerName, in);
}

/**
Expand Down Expand Up @@ -132,14 +134,11 @@ Collector create(Collector in) {

@Override
protected InternalProfileCollector createWithProfiler(InternalProfileCollector in) {
final List<InternalProfileCollector> subCollectors = new ArrayList<>();
subCollectors.add(in);
if (subCollector instanceof InternalProfileCollector == false) {
throw new IllegalArgumentException("non-profiling collector");
}
subCollectors.add((InternalProfileCollector) subCollector);
final Collector collector = MultiCollector.wrap(subCollectors);
return new InternalProfileCollector(collector, REASON_SEARCH_MULTI, subCollectors);
final Collector collector = MultiCollector.wrap(in, subCollector);
return new InternalProfileCollector(collector, REASON_SEARCH_MULTI, in, (InternalProfileCollector) subCollector);
}
};
}
Expand Down