Search in sources :

Example 6 with ErrorCode

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();
}
Also used : QueryStats(io.trino.execution.QueryStats) BasicQueryInfo(io.trino.server.BasicQueryInfo) TableMetadataBuilder.tableMetadataBuilder(io.trino.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Builder(io.trino.spi.connector.InMemoryRecordSet.Builder) BlockBuilder(io.trino.spi.block.BlockBuilder) ErrorCode(io.trino.spi.ErrorCode) BasicQueryInfo(io.trino.server.BasicQueryInfo) QueryInfo(io.trino.execution.QueryInfo)

Example 7 with ErrorCode

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();
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) HttpRemoteTaskFactory(io.trino.server.HttpRemoteTaskFactory) RemoteTask(io.trino.execution.RemoteTask) ErrorCode(io.trino.spi.ErrorCode)

Example 8 with ErrorCode

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);
}
Also used : ExecutionFailureInfo(io.trino.execution.ExecutionFailureInfo) FailureInfo(io.trino.client.FailureInfo) QueryState(io.trino.execution.QueryState) ErrorCode(io.trino.spi.ErrorCode) QueryError(io.trino.client.QueryError) ExecutionFailureInfo(io.trino.execution.ExecutionFailureInfo)

Example 9 with ErrorCode

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);
}
Also used : TrinoTransportException(io.trino.spi.TrinoTransportException) Objects(java.util.Objects) ErrorCode(io.trino.spi.ErrorCode) StandardErrorCode(io.trino.spi.StandardErrorCode) HostAddress(io.trino.spi.HostAddress) Failure(io.trino.execution.Failure) ExecutionFailureInfo(io.trino.execution.ExecutionFailureInfo)

Aggregations

ErrorCode (io.trino.spi.ErrorCode)9 ExecutionFailureInfo (io.trino.execution.ExecutionFailureInfo)3 BasicQueryInfo (io.trino.server.BasicQueryInfo)3 RemoteTask (io.trino.execution.RemoteTask)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 VerifyException (com.google.common.base.VerifyException)1 MoreFutures.asVoid (io.airlift.concurrent.MoreFutures.asVoid)1 Request (io.airlift.http.client.Request)1 JettyHttpClient (io.airlift.http.client.jetty.JettyHttpClient)1 Duration (io.airlift.units.Duration)1 FailureInfo (io.trino.client.FailureInfo)1 QueryError (io.trino.client.QueryError)1 QueryResults (io.trino.client.QueryResults)1 Failure (io.trino.execution.Failure)1 QueryOutputInfo (io.trino.execution.QueryExecution.QueryOutputInfo)1 QueryInfo (io.trino.execution.QueryInfo)1 QueryState (io.trino.execution.QueryState)1 QueryStats (io.trino.execution.QueryStats)1 TaskId (io.trino.execution.TaskId)1 TaskState (io.trino.execution.TaskState)1