Skip to content

Commit 1b5dc39

Browse files
committed
Enhance Parent circuit breaker error message (#32056)
* Enhance Parent circuit breaker error message This adds information about either the current real usage (if tracking "real" memory usage) or the child breaker usages to the exception message when the parent circuit breaker trips. The messages now look like: ``` [parent] Data too large, data for [my_request] would be [211288064/201.5mb], which is larger than the limit of [209715200/200mb], usages [request=157286400/150mb, fielddata=54001664/51.5mb, in_flight_requests=0/0b, accounting=0/0b] ``` Or when tracking real memory usage: ``` [parent] Data too large, data for [request] would be [251/251b], which is larger than the limit of [200/200b], real usage: [181/181b], new bytes reserved: [70/70b] ``` * Only call currentMemoryUsage once by returning structured object
1 parent f8c812e commit 1b5dc39

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

server/src/main/java/org/elasticsearch/indices/breaker/HierarchyCircuitBreakerService.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.concurrent.ConcurrentHashMap;
3636
import java.util.concurrent.ConcurrentMap;
3737
import java.util.concurrent.atomic.AtomicLong;
38+
import java.util.stream.Collectors;
3839

3940
/**
4041
* CircuitBreakerService that attempts to redistribute space between breakers
@@ -201,7 +202,7 @@ public AllCircuitBreakerStats stats() {
201202
}
202203
// Manually add the parent breaker settings since they aren't part of the breaker map
203204
allStats.add(new CircuitBreakerStats(CircuitBreaker.PARENT, parentSettings.getLimit(),
204-
parentEstimated, 1.0, parentTripCount.get()));
205+
parentEstimated, 1.0, parentTripCount.get()));
205206
return new AllCircuitBreakerStats(allStats.toArray(new CircuitBreakerStats[allStats.size()]));
206207
}
207208

@@ -223,11 +224,20 @@ public void checkParentLimit(String label) throws CircuitBreakingException {
223224
long parentLimit = this.parentSettings.getLimit();
224225
if (totalUsed > parentLimit) {
225226
this.parentTripCount.incrementAndGet();
226-
final String message = "[parent] Data too large, data for [" + label + "]" +
227+
final StringBuilder message = new StringBuilder("[parent] Data too large, data for [" + label + "]" +
227228
" would be [" + totalUsed + "/" + new ByteSizeValue(totalUsed) + "]" +
228229
", which is larger than the limit of [" +
229-
parentLimit + "/" + new ByteSizeValue(parentLimit) + "]";
230-
throw new CircuitBreakingException(message, totalUsed, parentLimit);
230+
parentLimit + "/" + new ByteSizeValue(parentLimit) + "]");
231+
message.append(", usages [");
232+
message.append(String.join(", ",
233+
this.breakers.entrySet().stream().map(e -> {
234+
final CircuitBreaker breaker = e.getValue();
235+
final long breakerUsed = (long)(breaker.getUsed() * breaker.getOverhead());
236+
return e.getKey() + "=" + breakerUsed + "/" + new ByteSizeValue(breakerUsed);
237+
})
238+
.collect(Collectors.toList())));
239+
message.append("]");
240+
throw new CircuitBreakingException(message.toString(), totalUsed, parentLimit);
231241
}
232242
}
233243

server/src/test/java/org/elasticsearch/indices/breaker/HierarchyCircuitBreakerServiceTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ public void testBorrowingSiblingBreakerMemory() throws Exception {
197197
.addEstimateBytesAndMaybeBreak(new ByteSizeValue(50, ByteSizeUnit.MB).getBytes(), "should break"));
198198
assertThat(exception.getMessage(), containsString("[parent] Data too large, data for [should break] would be"));
199199
assertThat(exception.getMessage(), containsString("which is larger than the limit of [209715200/200mb]"));
200+
assertThat(exception.getMessage(),
201+
containsString("usages [request=157286400/150mb, fielddata=54001664/51.5mb, in_flight_requests=0/0b, accounting=0/0b]"));
200202
}
201203
}
202204
}

0 commit comments

Comments
 (0)