use of org.elasticsearch.indices.breaker.CircuitBreakerService 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());
}
use of org.elasticsearch.indices.breaker.CircuitBreakerService 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));
}
use of org.elasticsearch.indices.breaker.CircuitBreakerService in project elasticsearch by elastic.
the class AggregatorTestCase method createAggregator.
protected <A extends Aggregator, B extends AggregationBuilder> A createAggregator(B aggregationBuilder, IndexSearcher indexSearcher, MappedFieldType... fieldTypes) throws IOException {
IndexSettings indexSettings = createIndexSettings();
SearchContext searchContext = createSearchContext(indexSearcher, indexSettings);
CircuitBreakerService circuitBreakerService = new NoneCircuitBreakerService();
when(searchContext.bigArrays()).thenReturn(new MockBigArrays(Settings.EMPTY, circuitBreakerService));
// TODO: now just needed for top_hits, this will need to be revised for other agg unit tests:
MapperService mapperService = mapperServiceMock();
when(mapperService.hasNested()).thenReturn(false);
when(searchContext.mapperService()).thenReturn(mapperService);
IndexFieldDataService ifds = new IndexFieldDataService(indexSettings, new IndicesFieldDataCache(Settings.EMPTY, new IndexFieldDataCache.Listener() {
}), circuitBreakerService, mapperService);
when(searchContext.fieldData()).thenReturn(ifds);
SearchLookup searchLookup = new SearchLookup(mapperService, ifds, new String[] { "type" });
when(searchContext.lookup()).thenReturn(searchLookup);
QueryShardContext queryShardContext = queryShardContextMock(fieldTypes, indexSettings, circuitBreakerService);
when(searchContext.getQueryShardContext()).thenReturn(queryShardContext);
@SuppressWarnings("unchecked") A aggregator = (A) aggregationBuilder.build(searchContext, null).create(null, true);
return aggregator;
}
use of org.elasticsearch.indices.breaker.CircuitBreakerService in project elasticsearch by elastic.
the class MemoryCircuitBreakerTests method testThreadedUpdatesToChildBreaker.
public void testThreadedUpdatesToChildBreaker() throws Exception {
final int NUM_THREADS = scaledRandomIntBetween(3, 15);
final int BYTES_PER_THREAD = scaledRandomIntBetween(500, 4500);
final Thread[] threads = new Thread[NUM_THREADS];
final AtomicBoolean tripped = new AtomicBoolean(false);
final AtomicReference<Throwable> lastException = new AtomicReference<>(null);
final AtomicReference<ChildMemoryCircuitBreaker> breakerRef = new AtomicReference<>(null);
final CircuitBreakerService service = new HierarchyCircuitBreakerService(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)) {
@Override
public CircuitBreaker getBreaker(String name) {
return breakerRef.get();
}
@Override
public void checkParentLimit(String label) throws CircuitBreakingException {
// never trip
}
};
final BreakerSettings settings = new BreakerSettings(CircuitBreaker.REQUEST, (BYTES_PER_THREAD * NUM_THREADS) - 1, 1.0);
final ChildMemoryCircuitBreaker breaker = new ChildMemoryCircuitBreaker(settings, logger, (HierarchyCircuitBreakerService) service, CircuitBreaker.REQUEST);
breakerRef.set(breaker);
for (int i = 0; i < NUM_THREADS; i++) {
threads[i] = new Thread(new Runnable() {
@Override
public void run() {
for (int j = 0; j < BYTES_PER_THREAD; j++) {
try {
breaker.addEstimateBytesAndMaybeBreak(1L, "test");
} catch (CircuitBreakingException e) {
if (tripped.get()) {
assertThat("tripped too many times", true, equalTo(false));
} else {
assertThat(tripped.compareAndSet(false, true), equalTo(true));
}
} catch (Exception e) {
lastException.set(e);
}
}
}
});
threads[i].start();
}
for (Thread t : threads) {
t.join();
}
assertThat("no other exceptions were thrown", lastException.get(), equalTo(null));
assertThat("breaker was tripped", tripped.get(), equalTo(true));
assertThat("breaker was tripped at least once", breaker.getTrippedCount(), greaterThanOrEqualTo(1L));
}
use of org.elasticsearch.indices.breaker.CircuitBreakerService in project elasticsearch by elastic.
the class NetworkModuleTests method testOverrideDefault.
public void testOverrideDefault() {
Settings settings = Settings.builder().put(NetworkModule.HTTP_TYPE_SETTING.getKey(), "custom").put(NetworkModule.HTTP_DEFAULT_TYPE_SETTING.getKey(), "default_custom").put(NetworkModule.TRANSPORT_DEFAULT_TYPE_SETTING.getKey(), "local").put(NetworkModule.TRANSPORT_TYPE_KEY, "default_custom").build();
// content doesn't matter we check reference equality
Supplier<Transport> customTransport = () -> null;
Supplier<HttpServerTransport> custom = FakeHttpTransport::new;
Supplier<HttpServerTransport> def = FakeHttpTransport::new;
NetworkModule module = newNetworkModule(settings, false, new NetworkPlugin() {
@Override
public Map<String, Supplier<Transport>> getTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays, CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry, NetworkService networkService) {
return Collections.singletonMap("default_custom", customTransport);
}
@Override
public Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays, CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry, NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher requestDispatcher) {
Map<String, Supplier<HttpServerTransport>> supplierMap = new HashMap<>();
supplierMap.put("custom", custom);
supplierMap.put("default_custom", def);
return supplierMap;
}
});
assertSame(custom, module.getHttpServerTransportSupplier());
assertSame(customTransport, module.getTransportSupplier());
}
Aggregations