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