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
5 changes: 5 additions & 0 deletions docs/changelog/102511.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 102511
summary: Trigger parent circuit breaker when building scorers in filters aggregation
area: Aggregations
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ public final Function<byte[], Number> pointReaderIfAvailable(ValuesSourceConfig
* @return the cumulative size in bytes allocated by this aggregator to service this request
*/
protected long addRequestCircuitBreakerBytes(long bytes) {
// Only use the potential to circuit break if bytes are being incremented
if (bytes > 0) {
// Only use the potential to circuit break if bytes are being incremented, In the case of 0
// bytes, it will trigger the parent circuit breaker.
if (bytes >= 0) {
context.breaker().addEstimateBytesAndMaybeBreak(bytes, "<agg [" + name + "]>");
} else {
context.breaker().addWithoutBreaking(bytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,17 @@ protected LeafBucketCollector getLeafCollector(AggregationExecutionContext aggCt
final int numFilters = filters().size();
List<FilterMatchingDisiWrapper> filterWrappers = new ArrayList<>();
long totalCost = 0;
// trigger the parent circuit breaker to make sure we have enough heap to build the first scorer.
// note we might still fail if the scorer is huge.
addRequestCircuitBreakerBytes(0L);
for (int filterOrd = 0; filterOrd < numFilters; filterOrd++) {
Scorer randomAccessScorer = filters().get(filterOrd).randomAccessScorer(aggCtx.getLeafReaderContext());
if (randomAccessScorer == null) {
continue;
}
// scorer can take a fair amount of heap, and we have no means to estimate the size, so
// we trigger the parent circuit breaker to at least fail if we are running out of heap
addRequestCircuitBreakerBytes(0L);
totalCost += randomAccessScorer.iterator().cost();
filterWrappers.add(
randomAccessScorer.twoPhaseIterator() == null
Expand Down