Search in sources :

Example 6 with JobContext

use of io.crate.expression.reference.sys.job.JobContext in project crate by crate.

the class JobsLogs method logPreExecutionFailure.

/**
 * Create a entry into `sys.jobs_log`
 * This method can be used instead of {@link #logExecutionEnd(UUID, String)} if there was no {@link #logExecutionStart(UUID, String, User, StatementClassifier.Classification)}
 * Call because an error happened during parse, analysis or plan.
 * <p>
 * {@link #logExecutionStart(UUID, String, User, StatementClassifier.Classification)} is only called after a Plan has been created and execution starts.
 */
public void logPreExecutionFailure(UUID jobId, String stmt, String errorMessage, User user) {
    JobContextLog jobContextLog = new JobContextLog(new JobContext(jobId, stmt, System.currentTimeMillis(), user, new StatementClassifier.Classification(UNDEFINED)), errorMessage);
    long stamp = jobsLogLock.readLock();
    try {
        jobsLog.add(jobContextLog);
    } finally {
        jobsLogLock.unlockRead(stamp);
    }
    recordMetrics(jobContextLog);
}
Also used : JobContextLog(io.crate.expression.reference.sys.job.JobContextLog) JobContext(io.crate.expression.reference.sys.job.JobContext)

Example 7 with JobContext

use of io.crate.expression.reference.sys.job.JobContext in project crate by crate.

the class JobsLogsTest method testLogsArentWipedOnSizeChange.

@Test
public void testLogsArentWipedOnSizeChange() {
    Settings settings = Settings.builder().put(JobsLogService.STATS_ENABLED_SETTING.getKey(), true).build();
    JobsLogService stats = new JobsLogService(settings, clusterService::localNode, clusterSettings, nodeCtx, scheduler, breakerService);
    LogSink<JobContextLog> jobsLogSink = (LogSink<JobContextLog>) stats.get().jobsLog();
    LogSink<OperationContextLog> operationsLogSink = (LogSink<OperationContextLog>) stats.get().operationsLog();
    Classification classification = new Classification(SELECT, Collections.singleton("Collect"));
    jobsLogSink.add(new JobContextLog(new JobContext(UUID.randomUUID(), "select 1", 1L, User.CRATE_USER, classification), null));
    clusterSettings.applySettings(Settings.builder().put(JobsLogService.STATS_ENABLED_SETTING.getKey(), true).put(JobsLogService.STATS_JOBS_LOG_SIZE_SETTING.getKey(), 200).build());
    assertThat(StreamSupport.stream(stats.get().jobsLog().spliterator(), false).count(), is(1L));
    operationsLogSink.add(new OperationContextLog(new OperationContext(1, UUID.randomUUID(), "foo", 2L, () -> -1), null));
    operationsLogSink.add(new OperationContextLog(new OperationContext(1, UUID.randomUUID(), "foo", 3L, () -> 1), null));
    clusterSettings.applySettings(Settings.builder().put(JobsLogService.STATS_ENABLED_SETTING.getKey(), true).put(JobsLogService.STATS_OPERATIONS_LOG_SIZE_SETTING.getKey(), 1).build());
    assertThat(StreamSupport.stream(stats.get().operationsLog().spliterator(), false).count(), is(1L));
}
Also used : OperationContext(io.crate.expression.reference.sys.operation.OperationContext) OperationContextLog(io.crate.expression.reference.sys.operation.OperationContextLog) JobContextLog(io.crate.expression.reference.sys.job.JobContextLog) Classification(io.crate.planner.operators.StatementClassifier.Classification) JobContext(io.crate.expression.reference.sys.job.JobContext) Settings(org.elasticsearch.common.settings.Settings) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 8 with JobContext

use of io.crate.expression.reference.sys.job.JobContext in project crate by crate.

the class StaticTableDefinitionTest method testTableDefinitionWithPredicate.

@Test
public void testTableDefinitionWithPredicate() throws ExecutionException, InterruptedException {
    List<JobContext> actual = List.of(new JobContext(UUID.randomUUID(), "select 1", 1L, CRATE_USER, null), new JobContext(UUID.randomUUID(), "select 2", 1L, CRATE_USER, null), new JobContext(UUID.randomUUID(), "select 3", 1L, dummyUser, null));
    StaticTableDefinition<JobContext> tableDef = new StaticTableDefinition<>(() -> completedFuture(actual), Map.of(), (user, ctx) -> user.isSuperUser() || ctx.username().equals(user.name()), true);
    Iterable<JobContext> expected = tableDef.retrieveRecords(dummyTxnCtx, CRATE_USER).get();
    assertThat(StreamSupport.stream(expected.spliterator(), false).count(), is(3L));
    expected = tableDef.retrieveRecords(dummyTxnCtx, dummyUser).get();
    assertThat(StreamSupport.stream(expected.spliterator(), false).count(), is(1L));
}
Also used : JobContext(io.crate.expression.reference.sys.job.JobContext) Test(org.junit.Test)

Aggregations

JobContext (io.crate.expression.reference.sys.job.JobContext)8 JobContextLog (io.crate.expression.reference.sys.job.JobContextLog)5 Test (org.junit.Test)5 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)3 Classification (io.crate.planner.operators.StatementClassifier.Classification)2 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)2 Settings (org.elasticsearch.common.settings.Settings)2 OperationContext (io.crate.expression.reference.sys.operation.OperationContext)1 OperationContextLog (io.crate.expression.reference.sys.operation.OperationContextLog)1 StatementClassifier (io.crate.planner.operators.StatementClassifier)1 User (io.crate.user.User)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1