Skip to content

Commit

Permalink
Fix slice collectors to leaves association with profile enabled (open…
Browse files Browse the repository at this point in the history
…search-project#11134)

Signed-off-by: Ticheng Lin <[email protected]>
  • Loading branch information
ticheng-aws committed Nov 8, 2023
1 parent 0ba5d58 commit fc6a3f7
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ public AbstractProfileBreakdown<QueryTimingType> context(Object context) {
@Override
public Map<String, Long> toBreakdownMap() {
final Map<String, Long> topLevelBreakdownMapWithWeightTime = super.toBreakdownMap();
int totalLeafCount = 0;
for (List<LeafReaderContext> leaves : sliceCollectorsToLeaves.values()) {
totalLeafCount += leaves.size();
}
if (contexts.size() != totalLeafCount) {
// If the leaf counts in contexts map don't match those in sliceCollectorsToLeaves, this means that the current
// node is outside the concurrent search path, which occurred before the contextIndexSearcher::searchLeaf.
// For example, in the post filter query, we may create a profile node during filtered collector context creation.
// In this case, as there is no concurrent implementation, we can simply return the accumulated breakdown result
// instead of the statistical result.
final Map<String, Long> queryBreakdownMap = new HashMap<>(topLevelBreakdownMapWithWeightTime);
for (final AbstractProfileBreakdown<QueryTimingType> context : contexts.values()) {
for (final Map.Entry<String, Long> entry : context.toBreakdownMap().entrySet()) {
queryBreakdownMap.merge(entry.getKey(), entry.getValue(), Long::sum);
}
}
return queryBreakdownMap;
}
final long createWeightStartTime = topLevelBreakdownMapWithWeightTime.get(
QueryTimingType.CREATE_WEIGHT + TIMING_TYPE_START_TIME_SUFFIX
);
Expand All @@ -83,7 +101,7 @@ public Map<String, Long> toBreakdownMap() {
// creates a new weight and breakdown map for each rewritten query. This new breakdown map captures the timing information for
// the new rewritten query. The sliceCollectorsToLeaves is empty because this breakdown for rewritten query gets created later
// in search leaf path which doesn't have collector. Also, this is not needed since this breakdown is per leaf and there is no
// concurrency involved. An empty sliceCollectorsToLeaves could also happen in the case of early termination.
// concurrency involved.
AbstractProfileBreakdown<QueryTimingType> breakdown = contexts.values().iterator().next();
queryNodeTime = breakdown.toNodeTime() + createWeightTime;
maxSliceNodeTime = 0L;
Expand Down

0 comments on commit fc6a3f7

Please sign in to comment.