use of org.elasticsearch.common.breaker.CircuitBreakingException in project elasticsearch by elastic.
the class ExceptionSerializationTests method testCircuitBreakingException.
public void testCircuitBreakingException() throws IOException {
CircuitBreakingException ex = serialize(new CircuitBreakingException("I hate to say I told you so...", 0, 100));
assertEquals("I hate to say I told you so...", ex.getMessage());
assertEquals(100, ex.getByteLimit());
assertEquals(0, ex.getBytesWanted());
}
use of org.elasticsearch.common.breaker.CircuitBreakingException in project elasticsearch by elastic.
the class BigArraysTests method testMaxSizeExceededOnNew.
public void testMaxSizeExceededOnNew() throws Exception {
final int size = scaledRandomIntBetween(5, 1 << 22);
for (String type : Arrays.asList("Byte", "Int", "Long", "Float", "Double", "Object")) {
HierarchyCircuitBreakerService hcbs = new HierarchyCircuitBreakerService(Settings.builder().put(HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING.getKey(), size - 1, ByteSizeUnit.BYTES).build(), new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
BigArrays bigArrays = new BigArrays(null, hcbs, false).withCircuitBreaking();
Method create = BigArrays.class.getMethod("new" + type + "Array", long.class);
try {
create.invoke(bigArrays, size);
fail("expected an exception on " + create);
} catch (InvocationTargetException e) {
assertTrue(e.getCause() instanceof CircuitBreakingException);
}
assertEquals(0, hcbs.getBreaker(CircuitBreaker.REQUEST).getUsed());
}
}
use of org.elasticsearch.common.breaker.CircuitBreakingException in project elasticsearch by elastic.
the class BigArraysTests method testMaxSizeExceededOnResize.
public void testMaxSizeExceededOnResize() throws Exception {
for (String type : Arrays.asList("Byte", "Int", "Long", "Float", "Double", "Object")) {
final long maxSize = randomIntBetween(1 << 10, 1 << 22);
HierarchyCircuitBreakerService hcbs = new HierarchyCircuitBreakerService(Settings.builder().put(HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING.getKey(), maxSize, ByteSizeUnit.BYTES).build(), new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
BigArrays bigArrays = new BigArrays(null, hcbs, false).withCircuitBreaking();
Method create = BigArrays.class.getMethod("new" + type + "Array", long.class);
final int size = scaledRandomIntBetween(1, 20);
BigArray array = (BigArray) create.invoke(bigArrays, size);
Method resize = BigArrays.class.getMethod("resize", array.getClass().getInterfaces()[0], long.class);
while (true) {
long newSize = array.size() * 2;
try {
array = (BigArray) resize.invoke(bigArrays, array, newSize);
} catch (InvocationTargetException e) {
assertTrue(e.getCause() instanceof CircuitBreakingException);
break;
}
}
assertEquals(array.ramBytesUsed(), hcbs.getBreaker(CircuitBreaker.REQUEST).getUsed());
array.close();
assertEquals(0, hcbs.getBreaker(CircuitBreaker.REQUEST).getUsed());
}
}
use of org.elasticsearch.common.breaker.CircuitBreakingException in project crate by crate.
the class HierarchyCircuitBreakerService method checkParentLimit.
/**
* Checks whether the parent breaker has been tripped
*/
public void checkParentLimit(long newBytesReserved, String label) throws CircuitBreakingException {
long totalUsed = parentUsed(newBytesReserved);
long parentLimit = this.parentSettings.getLimit();
if (totalUsed > parentLimit) {
long breakersTotalUsed = breakers.values().stream().mapToLong(CircuitBreaker::getUsed).sum();
// We want to allow the query so that it triggers GCs
if ((breakersTotalUsed + newBytesReserved) < (parentLimit * PARENT_BREAKER_ESCAPE_HATCH_PERCENTAGE)) {
return;
}
this.parentTripCount.incrementAndGet();
final StringBuilder message = new StringBuilder("[parent] Data too large, data for [" + label + "]" + " would be [" + totalUsed + "/" + new ByteSizeValue(totalUsed) + "]" + ", which is larger than the limit of [" + parentLimit + "/" + new ByteSizeValue(parentLimit) + "]");
message.append(", usages [");
message.append(this.breakers.entrySet().stream().map(e -> {
final CircuitBreaker breaker = e.getValue();
final long breakerUsed = breaker.getUsed();
return e.getKey() + "=" + breakerUsed + "/" + new ByteSizeValue(breakerUsed);
}).collect(Collectors.joining(", ")));
message.append("]");
throw new CircuitBreakingException(message.toString(), totalUsed, parentLimit);
}
}
use of org.elasticsearch.common.breaker.CircuitBreakingException in project crate by crate.
the class DistributingConsumerTest method test_exception_on_loadNextBatch_is_forwarded.
@Test
public void test_exception_on_loadNextBatch_is_forwarded() throws Exception {
Streamer<?>[] streamers = { DataTypes.INTEGER.streamer() };
TestingRowConsumer collectingConsumer = new TestingRowConsumer();
DistResultRXTask distResultRXTask = createPageDownstreamContext(streamers, collectingConsumer);
TransportDistributedResultAction distributedResultAction = createFakeTransport(streamers, distResultRXTask);
DistributingConsumer distributingConsumer = createDistributingConsumer(streamers, distributedResultAction);
BatchSimulatingIterator<Row> batchSimulatingIterator = new BatchSimulatingIterator<>(TestingBatchIterators.range(0, 5), 2, 3, executorService) {
@Override
public CompletionStage<?> loadNextBatch() {
throw new CircuitBreakingException("data too large");
}
};
distributingConsumer.accept(batchSimulatingIterator, null);
expectedException.expect(CircuitBreakingException.class);
collectingConsumer.getResult();
}
Aggregations