Search in sources :

Example 1 with NoopCircuitBreaker

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

the class HierarchyCircuitBreakerService method registerBreaker.

/**
     * Allows to register a custom circuit breaker.
     * Warning: Will overwrite any existing custom breaker with the same name.
     */
@Override
public void registerBreaker(BreakerSettings breakerSettings) {
    // Validate the settings
    validateSettings(new BreakerSettings[] { breakerSettings });
    if (breakerSettings.getType() == CircuitBreaker.Type.NOOP) {
        CircuitBreaker breaker = new NoopCircuitBreaker(breakerSettings.getName());
        breakers.put(breakerSettings.getName(), breaker);
    } else {
        CircuitBreaker oldBreaker;
        CircuitBreaker breaker = new ChildMemoryCircuitBreaker(breakerSettings, Loggers.getLogger(CHILD_LOGGER_PREFIX + breakerSettings.getName()), this, breakerSettings.getName());
        for (; ; ) {
            oldBreaker = breakers.putIfAbsent(breakerSettings.getName(), breaker);
            if (oldBreaker == null) {
                return;
            }
            breaker = new ChildMemoryCircuitBreaker(breakerSettings, (ChildMemoryCircuitBreaker) oldBreaker, Loggers.getLogger(CHILD_LOGGER_PREFIX + breakerSettings.getName()), this, breakerSettings.getName());
            if (breakers.replace(breakerSettings.getName(), oldBreaker, breaker)) {
                return;
            }
        }
    }
}
Also used : ChildMemoryCircuitBreaker(org.elasticsearch.common.breaker.ChildMemoryCircuitBreaker) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) NoopCircuitBreaker(org.elasticsearch.common.breaker.NoopCircuitBreaker) NoopCircuitBreaker(org.elasticsearch.common.breaker.NoopCircuitBreaker) ChildMemoryCircuitBreaker(org.elasticsearch.common.breaker.ChildMemoryCircuitBreaker)

Example 2 with NoopCircuitBreaker

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

the class LuceneBatchIteratorTest method testLuceneBatchIterator.

@Test
public void testLuceneBatchIterator() throws Exception {
    BatchIteratorTester tester = new BatchIteratorTester(() -> {
        return new LuceneBatchIterator(indexSearcher, new MatchAllDocsQuery(), null, false, new CollectorContext(mock(IndexFieldDataService.class), new CollectorFieldsVisitor(0)), new RamAccountingContext("dummy", new NoopCircuitBreaker("dummy")), columnRefs, columnRefs);
    });
    tester.verifyResultAndEdgeCaseBehaviour(expectedResult);
}
Also used : RamAccountingContext(io.crate.breaker.RamAccountingContext) BatchIteratorTester(io.crate.testing.BatchIteratorTester) CollectorContext(io.crate.operation.reference.doc.lucene.CollectorContext) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) NoopCircuitBreaker(org.elasticsearch.common.breaker.NoopCircuitBreaker) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 3 with NoopCircuitBreaker

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

the class NodeFetchOperationTest method testSysOperationsIsClearedIfNothingToFetch.

@Test
public void testSysOperationsIsClearedIfNothingToFetch() throws Exception {
    ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) Executors.newFixedThreadPool(1);
    try {
        JobsLogs jobsLogs = new JobsLogs(() -> true);
        NodeFetchOperation fetchOperation = new NodeFetchOperation(threadPoolExecutor, 2, jobsLogs, new TasksService(clusterService, jobsLogs), new NoopCircuitBreaker("dummy"));
        fetchOperation.fetch(UUID.randomUUID(), 1, null, true).get(5, TimeUnit.SECONDS);
        assertThat(StreamSupport.stream(jobsLogs.activeOperations().spliterator(), false).count(), is(0L));
    } finally {
        threadPoolExecutor.shutdown();
        threadPoolExecutor.awaitTermination(2, TimeUnit.SECONDS);
    }
}
Also used : TasksService(io.crate.execution.jobs.TasksService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) JobsLogs(io.crate.execution.engine.collect.stats.JobsLogs) NoopCircuitBreaker(org.elasticsearch.common.breaker.NoopCircuitBreaker) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 4 with NoopCircuitBreaker

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

the class WindowBatchIteratorTest method testWindowBatchIteratorAccountsUsedMemory.

@Test
public void testWindowBatchIteratorAccountsUsedMemory() {
    RamAccounting ramAccounting = ConcurrentRamAccounting.forCircuitBreaker("test", new NoopCircuitBreaker("dummy"));
    BatchIterator<Row> iterator = WindowFunctionBatchIterator.of(TestingBatchIterators.range(0, 10), new RowAccountingWithEstimators(List.of(DataTypes.INTEGER), ramAccounting, 32), (partitionStart, partitionEnd, currentIndex, sortedRows) -> 0, (partitionStart, partitionEnd, currentIndex, sortedRows) -> currentIndex, null, null, 1, () -> 1, Runnable::run, List.of(rowNumberWindowFunction()), List.of(), new Boolean[] { null }, new Input[][] { new Input[0] });
    TestingRowConsumer consumer = new TestingRowConsumer();
    consumer.accept(iterator, null);
    // should've accounted for 10 integers of 48 bytes each (16 for the integer, 32 for the ArrayList element)
    assertThat(ramAccounting.totalBytes(), is(480L));
}
Also used : RamAccounting(io.crate.breaker.RamAccounting) ConcurrentRamAccounting(io.crate.breaker.ConcurrentRamAccounting) RowAccountingWithEstimators(io.crate.breaker.RowAccountingWithEstimators) Row(io.crate.data.Row) NoopCircuitBreaker(org.elasticsearch.common.breaker.NoopCircuitBreaker) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Test(org.junit.Test)

Example 5 with NoopCircuitBreaker

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

the class SqlHttpHandlerTest method testUserIfHttpBasicAuthIsPresent.

@Test
public void testUserIfHttpBasicAuthIsPresent() {
    SqlHttpHandler handler = new SqlHttpHandler(Settings.EMPTY, mock(SQLOperations.class), (s) -> new NoopCircuitBreaker("dummy"), User::of, sessionContext -> AccessControl.DISABLED, Netty4CorsConfigBuilder.forAnyOrigin().build());
    User user = handler.userFromAuthHeader("Basic QWxhZGRpbjpPcGVuU2VzYW1l");
    assertThat(user.name(), is("Aladdin"));
}
Also used : User(io.crate.user.User) NoopCircuitBreaker(org.elasticsearch.common.breaker.NoopCircuitBreaker) SQLOperations(io.crate.action.sql.SQLOperations) Test(org.junit.Test)

Aggregations

NoopCircuitBreaker (org.elasticsearch.common.breaker.NoopCircuitBreaker)14 Test (org.junit.Test)10 CircuitBreaker (org.elasticsearch.common.breaker.CircuitBreaker)5 User (io.crate.user.User)4 SQLOperations (io.crate.action.sql.SQLOperations)3 Tuple (io.crate.common.collections.Tuple)3 Streams (io.crate.common.io.Streams)3 TimeValue (io.crate.common.unit.TimeValue)3 TestingRowConsumer (io.crate.testing.TestingRowConsumer)3 IOException (java.io.IOException)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 LongSupplier (java.util.function.LongSupplier)3 Predicate (java.util.function.Predicate)3 Supplier (java.util.function.Supplier)3 Version (org.elasticsearch.Version)3 BytesArray (org.elasticsearch.common.bytes.BytesArray)3 BytesReference (org.elasticsearch.common.bytes.BytesReference)3 ReleasableBytesReference (org.elasticsearch.common.bytes.ReleasableBytesReference)3 Row (io.crate.data.Row)2 RowN (io.crate.data.RowN)2