Search in sources :

Example 6 with BaseResultReceiver

use of io.crate.action.sql.BaseResultReceiver in project crate by crate.

the class RetryOnFailureResultReceiverTest method testRetryIsInvokedOnIndexNotFoundException.

@Test
public void testRetryIsInvokedOnIndexNotFoundException() throws Exception {
    AtomicInteger numRetries = new AtomicInteger(0);
    BaseResultReceiver resultReceiver = new BaseResultReceiver();
    ClusterState initialState = clusterService.state();
    RetryOnFailureResultReceiver retryOnFailureResultReceiver = new RetryOnFailureResultReceiver(clusterService, initialState, indexName -> true, resultReceiver, UUID.randomUUID(), (newJobId, receiver) -> numRetries.incrementAndGet());
    // Must have a different cluster state then the initial state to trigger a retry
    clusterService.submitStateUpdateTask("dummy", new DummyUpdate());
    assertBusy(() -> assertThat(initialState, Matchers.not(sameInstance(clusterService.state()))));
    retryOnFailureResultReceiver.fail(new IndexNotFoundException("t1"));
    assertThat(numRetries.get(), is(1));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BaseResultReceiver(io.crate.action.sql.BaseResultReceiver) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 7 with BaseResultReceiver

use of io.crate.action.sql.BaseResultReceiver in project crate by crate.

the class TableStatsService method updateStats.

public void updateStats() {
    if (clusterService.localNode() == null) {
        /*
              During a long startup (e.g. during an upgrade process) the localNode() may be null
              and this would lead to NullPointerException in the TransportExecutor.
             */
        LOGGER.debug("Could not retrieve table stats. localNode is not fully available yet.");
        return;
    }
    if (!clusterService.state().nodes().isLocalNodeElectedMaster()) {
        // `ANALYZE` will publish the new stats to all nodes, so we need only a single node running it.
        return;
    }
    try {
        BaseResultReceiver resultReceiver = new BaseResultReceiver();
        resultReceiver.completionFuture().whenComplete((res, err) -> {
            scheduledRefresh = scheduleNextRefresh(refreshInterval);
            if (err != null) {
                LOGGER.error("Error running periodic " + STMT + "", err);
            }
        });
        session.quickExec(STMT, stmt -> PARSED_STMT, resultReceiver, Row.EMPTY);
    } catch (Throwable t) {
        LOGGER.error("error retrieving table stats", t);
    }
}
Also used : BaseResultReceiver(io.crate.action.sql.BaseResultReceiver)

Aggregations

BaseResultReceiver (io.crate.action.sql.BaseResultReceiver)7 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)3 Test (org.junit.Test)3 Session (io.crate.action.sql.Session)2 RowConsumer (io.crate.data.RowConsumer)2 Planner (io.crate.planner.Planner)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ClusterState (org.elasticsearch.cluster.ClusterState)2 RowConsumerToResultReceiver (io.crate.action.sql.RowConsumerToResultReceiver)1 SQLOperations (io.crate.action.sql.SQLOperations)1 AnalyzedStatement (io.crate.analyze.AnalyzedStatement)1 Row (io.crate.data.Row)1 Row1 (io.crate.data.Row1)1 NodeOperationTree (io.crate.execution.dsl.phases.NodeOperationTree)1 JobsLogs (io.crate.execution.engine.collect.stats.JobsLogs)1 Symbol (io.crate.expression.symbol.Symbol)1 NodeContext (io.crate.metadata.NodeContext)1 SessionSettingRegistry (io.crate.metadata.settings.session.SessionSettingRegistry)1 DependencyCarrier (io.crate.planner.DependencyCarrier)1 ExecutionPlan (io.crate.planner.ExecutionPlan)1