use of io.trino.spi.ErrorCode in project trino by trinodb.
the class QuerySystemTable method cursor.
@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession session, TupleDomain<Integer> constraint) {
checkState(dispatchManager.isPresent(), "Query system table can return results only on coordinator");
List<BasicQueryInfo> queries = dispatchManager.get().getQueries();
queries = filterQueries(((FullConnectorSession) session).getSession().getIdentity(), queries, accessControl);
Builder table = InMemoryRecordSet.builder(QUERY_TABLE);
for (BasicQueryInfo queryInfo : queries) {
Optional<QueryInfo> fullQueryInfo = dispatchManager.get().getFullQueryInfo(queryInfo.getQueryId());
if (fullQueryInfo.isEmpty()) {
continue;
}
QueryStats queryStats = fullQueryInfo.get().getQueryStats();
table.addRow(queryInfo.getQueryId().toString(), queryInfo.getState().toString(), queryInfo.getSession().getUser(), queryInfo.getSession().getSource().orElse(null), queryInfo.getQuery(), queryInfo.getResourceGroupId().map(QuerySystemTable::resourceGroupIdToBlock).orElse(null), toMillis(queryStats.getQueuedTime()), toMillis(queryStats.getAnalysisTime()), toMillis(queryStats.getPlanningTime()), toTimestampWithTimeZoneMillis(queryStats.getCreateTime()), toTimestampWithTimeZoneMillis(queryStats.getExecutionStartTime()), toTimestampWithTimeZoneMillis(queryStats.getLastHeartbeat()), toTimestampWithTimeZoneMillis(queryStats.getEndTime()), Optional.ofNullable(queryInfo.getErrorType()).map(Enum::name).orElse(null), Optional.ofNullable(queryInfo.getErrorCode()).map(ErrorCode::getName).orElse(null));
}
return table.build().cursor();
}
use of io.trino.spi.ErrorCode in project trino by trinodb.
the class TestHttpRemoteTask method runTest.
private void runTest(FailureScenario failureScenario) throws Exception {
AtomicLong lastActivityNanos = new AtomicLong(System.nanoTime());
TestingTaskResource testingTaskResource = new TestingTaskResource(lastActivityNanos, failureScenario);
HttpRemoteTaskFactory httpRemoteTaskFactory = createHttpRemoteTaskFactory(testingTaskResource);
RemoteTask remoteTask = createRemoteTask(httpRemoteTaskFactory, ImmutableSet.of());
testingTaskResource.setInitialTaskInfo(remoteTask.getTaskInfo());
remoteTask.start();
waitUntilIdle(lastActivityNanos);
httpRemoteTaskFactory.stop();
assertTrue(remoteTask.getTaskStatus().getState().isDone(), format("TaskStatus is not in a done state: %s", remoteTask.getTaskStatus()));
ErrorCode actualErrorCode = getOnlyElement(remoteTask.getTaskStatus().getFailures()).getErrorCode();
switch(failureScenario) {
case TASK_MISMATCH:
case TASK_MISMATCH_WHEN_VERSION_IS_HIGH:
assertTrue(remoteTask.getTaskInfo().getTaskStatus().getState().isDone(), format("TaskInfo is not in a done state: %s", remoteTask.getTaskInfo()));
assertEquals(actualErrorCode, REMOTE_TASK_MISMATCH.toErrorCode());
break;
case REJECTED_EXECUTION:
// for a rejection to occur, the http client must be shutdown, which means we will not be able to ge the final task info
assertEquals(actualErrorCode, REMOTE_TASK_ERROR.toErrorCode());
break;
default:
throw new UnsupportedOperationException();
}
}
use of io.trino.spi.ErrorCode in project trino by trinodb.
the class Query method toQueryError.
private static QueryError toQueryError(QueryInfo queryInfo, Optional<Throwable> exception) {
QueryState state = queryInfo.getState();
if (state != FAILED && exception.isEmpty()) {
return null;
}
ExecutionFailureInfo executionFailure;
if (queryInfo.getFailureInfo() != null) {
executionFailure = queryInfo.getFailureInfo();
} else if (exception.isPresent()) {
executionFailure = toFailure(exception.get());
} else {
log.warn("Query %s in state %s has no failure info", queryInfo.getQueryId(), state);
executionFailure = toFailure(new RuntimeException(format("Query is %s (reason unknown)", state)));
}
FailureInfo failure = executionFailure.toFailureInfo();
ErrorCode errorCode;
if (queryInfo.getErrorCode() != null) {
errorCode = queryInfo.getErrorCode();
} else if (exception.isPresent()) {
errorCode = SERIALIZATION_ERROR.toErrorCode();
} else {
errorCode = GENERIC_INTERNAL_ERROR.toErrorCode();
log.warn("Failed query %s has no error code", queryInfo.getQueryId());
}
return new QueryError(firstNonNull(failure.getMessage(), "Internal error"), null, errorCode.getCode(), errorCode.getName(), errorCode.getType().toString(), failure.getErrorLocation(), failure);
}
use of io.trino.spi.ErrorCode in project trino by trinodb.
the class Failures method toFailure.
private static ExecutionFailureInfo toFailure(Throwable throwable, Set<Throwable> seenFailures) {
if (throwable == null) {
return null;
}
String type;
HostAddress remoteHost = null;
if (throwable instanceof Failure) {
type = ((Failure) throwable).getType();
} else {
Class<?> clazz = throwable.getClass();
type = firstNonNull(clazz.getCanonicalName(), clazz.getName());
}
if (throwable instanceof TrinoTransportException) {
remoteHost = ((TrinoTransportException) throwable).getRemoteHost();
}
if (seenFailures.contains(throwable)) {
return new ExecutionFailureInfo(type, "[cyclic] " + throwable.getMessage(), null, ImmutableList.of(), ImmutableList.of(), null, GENERIC_INTERNAL_ERROR.toErrorCode(), remoteHost);
}
seenFailures.add(throwable);
ExecutionFailureInfo cause = toFailure(throwable.getCause(), seenFailures);
ErrorCode errorCode = toErrorCode(throwable);
if (errorCode == null) {
if (cause == null) {
errorCode = GENERIC_INTERNAL_ERROR.toErrorCode();
} else {
errorCode = cause.getErrorCode();
}
}
return new ExecutionFailureInfo(type, throwable.getMessage(), cause, Arrays.stream(throwable.getSuppressed()).map(failure -> toFailure(failure, seenFailures)).collect(toImmutableList()), Arrays.stream(throwable.getStackTrace()).map(Objects::toString).collect(toImmutableList()), getErrorLocation(throwable), errorCode, remoteHost);
}
Aggregations