Search in sources :

Example 11 with CircuitBreakingException

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());
}
Also used : CircuitBreakingException(org.elasticsearch.common.breaker.CircuitBreakingException)

Example 12 with CircuitBreakingException

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());
    }
}
Also used : ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) CircuitBreakingException(org.elasticsearch.common.breaker.CircuitBreakingException) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 13 with CircuitBreakingException

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());
    }
}
Also used : ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) CircuitBreakingException(org.elasticsearch.common.breaker.CircuitBreakingException) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 14 with CircuitBreakingException

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);
    }
}
Also used : ChildMemoryCircuitBreaker(org.elasticsearch.common.breaker.ChildMemoryCircuitBreaker) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) NoopCircuitBreaker(org.elasticsearch.common.breaker.NoopCircuitBreaker) CircuitBreakingException(org.elasticsearch.common.breaker.CircuitBreakingException) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue)

Example 15 with CircuitBreakingException

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();
}
Also used : Streamer(io.crate.Streamer) BatchSimulatingIterator(io.crate.testing.BatchSimulatingIterator) CircuitBreakingException(org.elasticsearch.common.breaker.CircuitBreakingException) Row(io.crate.data.Row) DistResultRXTask(io.crate.execution.jobs.DistResultRXTask) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Test(org.junit.Test)

Aggregations

CircuitBreakingException (org.elasticsearch.common.breaker.CircuitBreakingException)17 ArrayList (java.util.ArrayList)7 BreakerSettings (org.elasticsearch.indices.breaker.BreakerSettings)5 Row (io.crate.data.Row)4 Client (org.elasticsearch.client.Client)4 CircuitBreaker (org.elasticsearch.common.breaker.CircuitBreaker)4 NoopCircuitBreaker (org.elasticsearch.common.breaker.NoopCircuitBreaker)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 IOException (java.io.IOException)3 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)3 Settings (org.elasticsearch.common.settings.Settings)3 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)3 RowAccounting (io.crate.breaker.RowAccounting)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 List (java.util.List)2 NodeStats (org.elasticsearch.action.admin.cluster.node.stats.NodeStats)2 NodesStatsResponse (org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse)2 ShardSearchFailure (org.elasticsearch.action.search.ShardSearchFailure)2 ChildMemoryCircuitBreaker (org.elasticsearch.common.breaker.ChildMemoryCircuitBreaker)2