Search in sources :

Example 6 with CircuitBreaker

use of org.elasticsearch.common.breaker.CircuitBreaker in project crate by crate.

the class RamAccountingQueueSinkTest method breaker.

public static CircuitBreaker breaker() {
    CircuitBreaker circuitBreaker = mock(CircuitBreaker.class);
    // mocked CircuitBreaker has unlimited memory (⌐■_■)
    when(circuitBreaker.getLimit()).thenReturn(Long.MAX_VALUE);
    return circuitBreaker;
}
Also used : CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker)

Example 7 with CircuitBreaker

use of org.elasticsearch.common.breaker.CircuitBreaker in project crate by crate.

the class CrateCircuitBreakerServiceTest method testBreakerSettingsAssignment.

@Test
public void testBreakerSettingsAssignment() throws Exception {
    Settings settings = Settings.builder().put(CrateCircuitBreakerService.QUERY_CIRCUIT_BREAKER_LIMIT_SETTING, "10m").put(CrateCircuitBreakerService.QUERY_CIRCUIT_BREAKER_OVERHEAD_SETTING, 1.0).build();
    final NodeSettingsService.Listener[] listeners = new NodeSettingsService.Listener[1];
    NodeSettingsService settingsService = new NodeSettingsService(settings) {

        @Override
        public void addListener(Listener listener) {
            listeners[0] = listener;
        }
    };
    CircuitBreakerService esBreakerService = spy(new HierarchyCircuitBreakerService(Settings.EMPTY, settingsService));
    CrateCircuitBreakerService breakerService = new CrateCircuitBreakerService(settings, settingsService, esBreakerService);
    CircuitBreaker breaker = breakerService.getBreaker(CrateCircuitBreakerService.QUERY);
    assertThat(breaker.getLimit(), is(10_485_760L));
    assertThat(breaker.getOverhead(), is(1.0));
    Settings newSettings = Settings.settingsBuilder().put(CrateCircuitBreakerService.QUERY_CIRCUIT_BREAKER_LIMIT_SETTING, "100m").put(CrateCircuitBreakerService.QUERY_CIRCUIT_BREAKER_OVERHEAD_SETTING, 2.0).build();
    listeners[0].onRefreshSettings(newSettings);
    // expecting 4 times because registerBreaker() is also called from constructor of CrateCircuitBreakerService 3 times
    verify(esBreakerService, times(4)).registerBreaker(Matchers.any());
    breaker = breakerService.getBreaker(CrateCircuitBreakerService.QUERY);
    assertThat(breaker.getLimit(), is(104_857_600L));
    assertThat(breaker.getOverhead(), is(2.0));
    // updating with same settings should not register a new breaker
    listeners[0].onRefreshSettings(newSettings);
    verify(esBreakerService, times(4)).registerBreaker(Matchers.any());
}
Also used : CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) NodeSettingsService(org.elasticsearch.node.settings.NodeSettingsService) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 8 with CircuitBreaker

use of org.elasticsearch.common.breaker.CircuitBreaker in project crate by crate.

the class CrateCircuitBreakerServiceTest method testQueryCircuitBreakerDynamicSettings.

@Test
public void testQueryCircuitBreakerDynamicSettings() throws Exception {
    final NodeSettingsService.Listener[] listeners = new NodeSettingsService.Listener[1];
    NodeSettingsService settingsService = new NodeSettingsService(Settings.EMPTY) {

        @Override
        public void addListener(Listener listener) {
            listeners[0] = listener;
        }
    };
    CircuitBreakerService esBreakerService = new HierarchyCircuitBreakerService(Settings.EMPTY, settingsService);
    CrateCircuitBreakerService breakerService = new CrateCircuitBreakerService(Settings.EMPTY, settingsService, esBreakerService);
    Settings newSettings = Settings.settingsBuilder().put(CrateCircuitBreakerService.QUERY_CIRCUIT_BREAKER_OVERHEAD_SETTING, 2.0).build();
    listeners[0].onRefreshSettings(newSettings);
    CircuitBreaker breaker = breakerService.getBreaker(CrateCircuitBreakerService.QUERY);
    assertThat(breaker, notNullValue());
    assertThat(breaker, instanceOf(CircuitBreaker.class));
    assertThat(breaker.getOverhead(), is(2.0));
}
Also used : CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) NodeSettingsService(org.elasticsearch.node.settings.NodeSettingsService) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 9 with CircuitBreaker

use of org.elasticsearch.common.breaker.CircuitBreaker in project elasticsearch by elastic.

the class InternalTestCluster method assertRequestsFinished.

private void assertRequestsFinished() {
    if (size() > 0) {
        for (NodeAndClient nodeAndClient : nodes.values()) {
            CircuitBreaker inFlightRequestsBreaker = getInstance(CircuitBreakerService.class, nodeAndClient.name).getBreaker(CircuitBreaker.IN_FLIGHT_REQUESTS);
            try {
                // see #ensureEstimatedStats()
                assertBusy(() -> {
                    // ensure that our size accounting on transport level is reset properly
                    long bytesUsed = inFlightRequestsBreaker.getUsed();
                    assertThat("All incoming requests on node [" + nodeAndClient.name + "] should have finished. Expected 0 but got " + bytesUsed, bytesUsed, equalTo(0L));
                });
            } catch (Exception e) {
                logger.error("Could not assert finished requests within timeout", e);
                fail("Could not assert finished requests within timeout on node [" + nodeAndClient.name + "]");
            }
        }
    }
}
Also used : CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) CircuitBreakerService(org.elasticsearch.indices.breaker.CircuitBreakerService) HierarchyCircuitBreakerService(org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService) NodeValidationException(org.elasticsearch.node.NodeValidationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ElasticsearchException(org.elasticsearch.ElasticsearchException) ShardLockObtainFailedException(org.elasticsearch.env.ShardLockObtainFailedException)

Example 10 with CircuitBreaker

use of org.elasticsearch.common.breaker.CircuitBreaker in project elasticsearch by elastic.

the class HierarchyCircuitBreakerService method stats.

@Override
public AllCircuitBreakerStats stats() {
    long parentEstimated = 0;
    List<CircuitBreakerStats> allStats = new ArrayList<>();
    // estimations for each individual breaker
    for (CircuitBreaker breaker : this.breakers.values()) {
        allStats.add(stats(breaker.getName()));
        parentEstimated += breaker.getUsed();
    }
    // Manually add the parent breaker settings since they aren't part of the breaker map
    allStats.add(new CircuitBreakerStats(CircuitBreaker.PARENT, parentSettings.getLimit(), parentEstimated, 1.0, parentTripCount.get()));
    return new AllCircuitBreakerStats(allStats.toArray(new CircuitBreakerStats[allStats.size()]));
}
Also used : ChildMemoryCircuitBreaker(org.elasticsearch.common.breaker.ChildMemoryCircuitBreaker) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) NoopCircuitBreaker(org.elasticsearch.common.breaker.NoopCircuitBreaker) ArrayList(java.util.ArrayList)

Aggregations

CircuitBreaker (org.elasticsearch.common.breaker.CircuitBreaker)14 CircuitBreakerService (org.elasticsearch.indices.breaker.CircuitBreakerService)7 HierarchyCircuitBreakerService (org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService)7 Settings (org.elasticsearch.common.settings.Settings)5 NoopCircuitBreaker (org.elasticsearch.common.breaker.NoopCircuitBreaker)4 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)4 CrateUnitTest (io.crate.test.integration.CrateUnitTest)3 ClusterName (org.elasticsearch.cluster.ClusterName)3 ClusterState (org.elasticsearch.cluster.ClusterState)3 ChildMemoryCircuitBreaker (org.elasticsearch.common.breaker.ChildMemoryCircuitBreaker)3 NodeSettingsService (org.elasticsearch.node.settings.NodeSettingsService)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutionException (java.util.concurrent.ExecutionException)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 NodeStats (org.elasticsearch.action.admin.cluster.node.stats.NodeStats)2 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)2 CircuitBreakingException (org.elasticsearch.common.breaker.CircuitBreakingException)2 MasterFaultDetection (org.elasticsearch.discovery.zen.MasterFaultDetection)2