Search in sources :

Example 1 with JobsLogs

use of io.crate.execution.engine.collect.stats.JobsLogs in project crate by crate.

the class Session method singleExec.

@VisibleForTesting
CompletableFuture<?> singleExec(Portal portal, ResultReceiver<?> resultReceiver, int maxRows) {
    var activeConsumer = portal.activeConsumer();
    if (activeConsumer != null && activeConsumer.suspended()) {
        activeConsumer.replaceResultReceiver(resultReceiver, maxRows);
        activeConsumer.resume();
        return resultReceiver.completionFuture();
    }
    var jobId = UUIDs.dirtyUUID();
    var routingProvider = new RoutingProvider(Randomness.get().nextInt(), planner.getAwarenessAttributes());
    var clusterState = executor.clusterService().state();
    var txnCtx = new CoordinatorTxnCtx(sessionContext);
    var nodeCtx = executor.nodeContext();
    var params = new RowN(portal.params().toArray());
    var plannerContext = new PlannerContext(clusterState, routingProvider, jobId, txnCtx, nodeCtx, maxRows, params);
    var analyzedStmt = portal.analyzedStatement();
    String rawStatement = portal.preparedStmt().rawStatement();
    if (analyzedStmt == null) {
        String errorMsg = "Statement must have been analyzed: " + rawStatement;
        jobsLogs.logPreExecutionFailure(jobId, rawStatement, errorMsg, sessionContext.sessionUser());
        throw new IllegalStateException(errorMsg);
    }
    Plan plan;
    try {
        plan = planner.plan(analyzedStmt, plannerContext);
    } catch (Throwable t) {
        jobsLogs.logPreExecutionFailure(jobId, rawStatement, SQLExceptions.messageOf(t), sessionContext.sessionUser());
        throw t;
    }
    if (!analyzedStmt.isWriteOperation()) {
        resultReceiver = new RetryOnFailureResultReceiver(executor.clusterService(), clusterState, indexName -> executor.clusterService().state().metadata().hasIndex(indexName), resultReceiver, jobId, (newJobId, resultRec) -> retryQuery(newJobId, analyzedStmt, routingProvider, new RowConsumerToResultReceiver(resultRec, maxRows, new JobsLogsUpdateListener(newJobId, jobsLogs)), params, txnCtx, nodeCtx));
    }
    jobsLogs.logExecutionStart(jobId, rawStatement, sessionContext.sessionUser(), StatementClassifier.classify(plan));
    RowConsumerToResultReceiver consumer = new RowConsumerToResultReceiver(resultReceiver, maxRows, new JobsLogsUpdateListener(jobId, jobsLogs));
    portal.setActiveConsumer(consumer);
    plan.execute(executor, plannerContext, consumer, params, SubQueryResults.EMPTY);
    return resultReceiver.completionFuture();
}
Also used : ParamTypeHints(io.crate.analyze.ParamTypeHints) RetryOnFailureResultReceiver(io.crate.protocols.postgres.RetryOnFailureResultReceiver) Analyzer(io.crate.analyze.Analyzer) DependencyCarrier(io.crate.planner.DependencyCarrier) ClusterState(org.elasticsearch.cluster.ClusterState) Relations(io.crate.analyze.Relations) RowN(io.crate.data.RowN) TransactionState(io.crate.protocols.postgres.TransactionState) Map(java.util.Map) JobsLogsUpdateListener(io.crate.protocols.postgres.JobsLogsUpdateListener) TableInfo(io.crate.metadata.table.TableInfo) NodeContext(io.crate.metadata.NodeContext) AnalyzedStatement(io.crate.analyze.AnalyzedStatement) UUIDs(org.elasticsearch.common.UUIDs) UUID(java.util.UUID) Lists2(io.crate.common.collections.Lists2) List(java.util.List) Logger(org.apache.logging.log4j.Logger) AnalyzedDiscard(io.crate.analyze.AnalyzedDiscard) Row(io.crate.data.Row) Symbol(io.crate.expression.symbol.Symbol) AnalyzedBegin(io.crate.analyze.AnalyzedBegin) SubQueryResults(io.crate.planner.operators.SubQueryResults) Statement(io.crate.sql.tree.Statement) VisibleForTesting(io.crate.common.annotations.VisibleForTesting) Row1(io.crate.data.Row1) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) AnalyzedCommit(io.crate.analyze.AnalyzedCommit) AccessControl(io.crate.auth.AccessControl) QueriedSelectRelation(io.crate.analyze.QueriedSelectRelation) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) JobsLogs(io.crate.execution.engine.collect.stats.JobsLogs) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Portal(io.crate.protocols.postgres.Portal) Symbols(io.crate.expression.symbol.Symbols) FormatCodes(io.crate.protocols.postgres.FormatCodes) SqlParser(io.crate.sql.parser.SqlParser) Nullable(javax.annotation.Nullable) Iterator(java.util.Iterator) RelationInfo(io.crate.metadata.RelationInfo) Target(io.crate.sql.tree.DiscardStatement.Target) DataType(io.crate.types.DataType) Planner(io.crate.planner.Planner) RoutingProvider(io.crate.metadata.RoutingProvider) RowConsumer(io.crate.data.RowConsumer) StatementClassifier(io.crate.planner.operators.StatementClassifier) AbstractTableRelation(io.crate.analyze.relations.AbstractTableRelation) PlannerContext(io.crate.planner.PlannerContext) Plan(io.crate.planner.Plan) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) ReadOnlyException(io.crate.exceptions.ReadOnlyException) SQLExceptions(io.crate.exceptions.SQLExceptions) LogManager(org.apache.logging.log4j.LogManager) Randomness(org.elasticsearch.common.Randomness) AnalyzedDeallocate(io.crate.analyze.AnalyzedDeallocate) RoutingProvider(io.crate.metadata.RoutingProvider) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) Plan(io.crate.planner.Plan) RowN(io.crate.data.RowN) PlannerContext(io.crate.planner.PlannerContext) JobsLogsUpdateListener(io.crate.protocols.postgres.JobsLogsUpdateListener) RetryOnFailureResultReceiver(io.crate.protocols.postgres.RetryOnFailureResultReceiver) VisibleForTesting(io.crate.common.annotations.VisibleForTesting)

Example 2 with JobsLogs

use of io.crate.execution.engine.collect.stats.JobsLogs in project crate by crate.

the class DecommissioningServiceTest method init.

@Before
public void init() throws Exception {
    executorService = mock(ScheduledExecutorService.class, Answers.RETURNS_MOCKS);
    jobsLogs = new JobsLogs(() -> true);
    sqlOperations = mock(SQLOperations.class, Answers.RETURNS_MOCKS);
    decommissioningService = new TestableDecommissioningService(Settings.EMPTY, clusterService, jobsLogs, executorService, sqlOperations, () -> exited.set(true), mock(TransportClusterHealthAction.class), mock(TransportClusterUpdateSettingsAction.class));
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) JobsLogs(io.crate.execution.engine.collect.stats.JobsLogs) SQLOperations(io.crate.action.sql.SQLOperations) Before(org.junit.Before)

Example 3 with JobsLogs

use of io.crate.execution.engine.collect.stats.JobsLogs in project crate by crate.

the class RootTaskTest method testErrorMessageIsIncludedInStatsTableOnFailure.

@Test
public void testErrorMessageIsIncludedInStatsTableOnFailure() throws Throwable {
    JobsLogs jobsLogs = mock(JobsLogs.class);
    RootTask.Builder builder = new RootTask.Builder(logger, UUID.randomUUID(), "dummy-user", coordinatorNode, Collections.emptySet(), jobsLogs);
    Task task = new AbstractTask(0) {

        @Override
        public String name() {
            return "dummy";
        }

        @Override
        public long bytesUsed() {
            return -1;
        }
    };
    builder.addTask(task);
    RootTask rootTask = builder.build();
    rootTask.start();
    task.kill(new IllegalStateException("dummy"));
    verify(jobsLogs).operationFinished(anyInt(), any(UUID.class), eq("dummy"));
}
Also used : CollectTask(io.crate.execution.engine.collect.CollectTask) JobsLogs(io.crate.execution.engine.collect.stats.JobsLogs) UUID(java.util.UUID) Test(org.junit.Test)

Example 4 with JobsLogs

use of io.crate.execution.engine.collect.stats.JobsLogs in project crate by crate.

the class TasksServiceTest method prepare.

@Before
public void prepare() {
    JobsLogs jobsLogs = new JobsLogs(() -> true);
    tasksService = new TasksService(clusterService, jobsLogs);
}
Also used : JobsLogs(io.crate.execution.engine.collect.stats.JobsLogs) Before(org.junit.Before)

Example 5 with JobsLogs

use of io.crate.execution.engine.collect.stats.JobsLogs 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)

Aggregations

JobsLogs (io.crate.execution.engine.collect.stats.JobsLogs)14 UUID (java.util.UUID)5 AnalyzedStatement (io.crate.analyze.AnalyzedStatement)4 Row (io.crate.data.Row)4 RowConsumer (io.crate.data.RowConsumer)4 TasksService (io.crate.execution.jobs.TasksService)4 DependencyCarrier (io.crate.planner.DependencyCarrier)4 Plan (io.crate.planner.Plan)4 Planner (io.crate.planner.Planner)4 PlannerContext (io.crate.planner.PlannerContext)4 SubQueryResults (io.crate.planner.operators.SubQueryResults)4 Test (org.junit.Test)4 AnalyzedBegin (io.crate.analyze.AnalyzedBegin)3 AnalyzedCommit (io.crate.analyze.AnalyzedCommit)3 AnalyzedDeallocate (io.crate.analyze.AnalyzedDeallocate)3 AnalyzedDiscard (io.crate.analyze.AnalyzedDiscard)3 Analyzer (io.crate.analyze.Analyzer)3 ParamTypeHints (io.crate.analyze.ParamTypeHints)3 QueriedSelectRelation (io.crate.analyze.QueriedSelectRelation)3 Relations (io.crate.analyze.Relations)3