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();
}
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));
}
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"));
}
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);
}
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);
}
}
Aggregations