Search in sources :

Example 1 with ErrorCode

use of com.facebook.presto.spi.ErrorCode in project presto by prestodb.

the class TestPrestoSparkExecutionExceptionFactory method assertFailure.

private static void assertFailure(Failure failure, Throwable expected) {
    ErrorCode expectedErrorCode = expected instanceof PrestoException ? ((PrestoException) expected).getErrorCode() : GENERIC_INTERNAL_ERROR.toErrorCode();
    assertEquals(failure.getErrorCode(), expectedErrorCode);
    assertEquals(failure.getType(), expected.getClass().getName());
    assertEquals(failure.getMessage(), expected.getMessage());
    if (expected.getCause() != null) {
        assertNotNull(failure.getCause());
        assertFailure((Failure) failure.getCause(), expected.getCause());
    }
    if (expected.getSuppressed() != null) {
        assertNotNull(failure.getSuppressed());
        assertEquals(failure.getSuppressed().length, expected.getSuppressed().length);
        for (int i = 0; i < expected.getSuppressed().length; i++) {
            assertFailure((Failure) failure.getSuppressed()[i], expected.getSuppressed()[i]);
        }
    }
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) ErrorCode(com.facebook.presto.spi.ErrorCode)

Example 2 with ErrorCode

use of com.facebook.presto.spi.ErrorCode in project presto by prestodb.

the class QueryStateMachine method getQueryInfo.

public QueryInfo getQueryInfo(Optional<StageInfo> rootStage) {
    // Query state must be captured first in order to provide a
    // correct view of the query.  For example, building this
    // information, the query could finish, and the task states would
    // never be visible.
    QueryState state = queryState.get();
    ExecutionFailureInfo failureCause = null;
    ErrorCode errorCode = null;
    if (state == QueryState.FAILED) {
        failureCause = this.failureCause.get();
        if (failureCause != null) {
            errorCode = failureCause.getErrorCode();
        }
    }
    boolean completeInfo = getAllStages(rootStage).stream().allMatch(StageInfo::isFinalStageInfo);
    Optional<List<TaskId>> failedTasks;
    // Traversing all tasks is expensive, thus only construct failedTasks list when query finished.
    if (state.isDone()) {
        failedTasks = Optional.of(getAllStages(rootStage).stream().flatMap(stageInfo -> Streams.concat(ImmutableList.of(stageInfo.getLatestAttemptExecutionInfo()).stream(), stageInfo.getPreviousAttemptsExecutionInfos().stream())).flatMap(execution -> execution.getTasks().stream()).filter(taskInfo -> taskInfo.getTaskStatus().getState() == TaskState.FAILED).map(TaskInfo::getTaskId).collect(toImmutableList()));
    } else {
        failedTasks = Optional.empty();
    }
    List<StageId> runtimeOptimizedStages = getAllStages(rootStage).stream().filter(StageInfo::isRuntimeOptimized).map(StageInfo::getStageId).collect(toImmutableList());
    QueryStats queryStats = getQueryStats(rootStage);
    return new QueryInfo(queryId, session.toSessionRepresentation(), state, memoryPool.get().getId(), queryStats.isScheduled(), self, outputManager.getQueryOutputInfo().map(QueryOutputInfo::getColumnNames).orElse(ImmutableList.of()), query, expandedQuery.get(), preparedQuery, queryStats, Optional.ofNullable(setCatalog.get()), Optional.ofNullable(setSchema.get()), setSessionProperties, resetSessionProperties, setRoles, addedPreparedStatements, deallocatedPreparedStatements, Optional.ofNullable(startedTransactionId.get()), clearTransactionId.get(), updateType.get(), rootStage, failureCause, errorCode, warningCollector.getWarnings(), inputs.get(), output.get(), completeInfo, Optional.of(resourceGroup), queryType, failedTasks, runtimeOptimizedStages.isEmpty() ? Optional.empty() : Optional.of(runtimeOptimizedStages), addedSessionFunctions, removedSessionFunctions);
}
Also used : WarningCollector(com.facebook.presto.spi.WarningCollector) NOT_FOUND(com.facebook.presto.spi.StandardErrorCode.NOT_FOUND) SqlInvokedFunction(com.facebook.presto.spi.function.SqlInvokedFunction) FINISHING(com.facebook.presto.execution.QueryState.FINISHING) PLANNING(com.facebook.presto.execution.QueryState.PLANNING) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) EMPTY_STAGE_STATS(com.facebook.presto.execution.BasicStageExecutionStats.EMPTY_STAGE_STATS) GENERAL_POOL(com.facebook.presto.memory.LocalMemoryManager.GENERAL_POOL) TransactionId(com.facebook.presto.transaction.TransactionId) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) URI(java.net.URI) StageInfo.getAllStages(com.facebook.presto.execution.StageInfo.getAllStages) BasicQueryStats(com.facebook.presto.server.BasicQueryStats) ImmutableSet(com.google.common.collect.ImmutableSet) Predicate(java.util.function.Predicate) DISPATCHING(com.facebook.presto.execution.QueryState.DISPATCHING) WAITING_FOR_RESOURCES(com.facebook.presto.execution.QueryState.WAITING_FOR_RESOURCES) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Failures.toFailure(com.facebook.presto.util.Failures.toFailure) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) Ticker(com.google.common.base.Ticker) Streams(com.google.common.collect.Streams) GuardedBy(javax.annotation.concurrent.GuardedBy) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) List(java.util.List) USER_CANCELED(com.facebook.presto.spi.StandardErrorCode.USER_CANCELED) Optional(java.util.Optional) QueryOutputInfo(com.facebook.presto.execution.QueryExecution.QueryOutputInfo) WAITING_FOR_PREREQUISITES(com.facebook.presto.execution.QueryState.WAITING_FOR_PREREQUISITES) Logger(com.facebook.airlift.log.Logger) QUEUED(com.facebook.presto.execution.QueryState.QUEUED) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ErrorCode(com.facebook.presto.spi.ErrorCode) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DataSize.succinctBytes(io.airlift.units.DataSize.succinctBytes) PrestoException(com.facebook.presto.spi.PrestoException) VersionedMemoryPoolId(com.facebook.presto.memory.VersionedMemoryPoolId) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) TERMINAL_QUERY_STATES(com.facebook.presto.execution.QueryState.TERMINAL_QUERY_STATES) LinkedHashMap(java.util.LinkedHashMap) ImmutableList(com.google.common.collect.ImmutableList) ALREADY_EXISTS(com.facebook.presto.spi.StandardErrorCode.ALREADY_EXISTS) Objects.requireNonNull(java.util.Objects.requireNonNull) TransactionManager(com.facebook.presto.transaction.TransactionManager) Type(com.facebook.presto.common.type.Type) Nullable(javax.annotation.Nullable) SelectedRole(com.facebook.presto.spi.security.SelectedRole) RUNNING(com.facebook.presto.execution.QueryState.RUNNING) Executor(java.util.concurrent.Executor) Session(com.facebook.presto.Session) DateTime(org.joda.time.DateTime) FutureCallback(com.google.common.util.concurrent.FutureCallback) FINISHED(com.facebook.presto.execution.QueryState.FINISHED) TransactionInfo(com.facebook.presto.transaction.TransactionInfo) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) Futures(com.google.common.util.concurrent.Futures) StateChangeListener(com.facebook.presto.execution.StateMachine.StateChangeListener) SqlFunctionId(com.facebook.presto.spi.function.SqlFunctionId) QueryType(com.facebook.presto.spi.resourceGroups.QueryType) QueryId(com.facebook.presto.spi.QueryId) STARTING(com.facebook.presto.execution.QueryState.STARTING) Metadata(com.facebook.presto.metadata.Metadata) AccessControl(com.facebook.presto.security.AccessControl) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) BasicQueryStats(com.facebook.presto.server.BasicQueryStats) QueryOutputInfo(com.facebook.presto.execution.QueryExecution.QueryOutputInfo) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) ErrorCode(com.facebook.presto.spi.ErrorCode)

Example 3 with ErrorCode

use of com.facebook.presto.spi.ErrorCode in project presto-audit by yahoojapan.

the class TestHelper method createFailureEvent.

public QueryCompletedEvent createFailureEvent() {
    setUp();
    QueryMetadata metadata = new QueryMetadata("20170606_044544_00024_nfhe3", Optional.of("4c52973c-14c6-4534-837f-238e21d9b061"), "select 2a", "FAILED", uri, Optional.empty(), Optional.empty());
    ErrorCode errorCode = new ErrorCode(1, "SYNTAX_ERROR", ErrorType.USER_ERROR);
    QueryFailureInfo failureInfo = new QueryFailureInfo(errorCode, Optional.of("com.facebook.presto.sql.parser.ParsingException"), Optional.of("line 1:15: mismatched input '0' expecting ')'"), Optional.empty(), Optional.empty(), "{json-error}");
    return new QueryCompletedEvent(metadata, statistics, context, ioMetadata, Optional.of(failureInfo), createTime, executionStartTime, endTime);
}
Also used : QueryFailureInfo(com.facebook.presto.spi.eventlistener.QueryFailureInfo) QueryMetadata(com.facebook.presto.spi.eventlistener.QueryMetadata) QueryCompletedEvent(com.facebook.presto.spi.eventlistener.QueryCompletedEvent) ErrorCode(com.facebook.presto.spi.ErrorCode)

Example 4 with ErrorCode

use of com.facebook.presto.spi.ErrorCode in project presto by prestodb.

the class Query method toQueryError.

private static QueryError toQueryError(QueryInfo queryInfo) {
    QueryState state = queryInfo.getState();
    if (state != FAILED) {
        return null;
    }
    FailureInfo failure;
    if (queryInfo.getFailureInfo() != null) {
        failure = queryInfo.getFailureInfo().toFailureInfo();
    } else {
        log.warn("Query %s in state %s has no failure info", queryInfo.getQueryId(), state);
        failure = toFailure(new RuntimeException(format("Query is %s (reason unknown)", state))).toFailureInfo();
    }
    ErrorCode errorCode;
    if (queryInfo.getErrorCode() != null) {
        errorCode = queryInfo.getErrorCode();
    } 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(), errorCode.isRetriable(), failure.getErrorLocation(), failure);
}
Also used : FailureInfo(com.facebook.presto.client.FailureInfo) QueryState(com.facebook.presto.execution.QueryState) ErrorCode(com.facebook.presto.spi.ErrorCode) QueryError(com.facebook.presto.client.QueryError)

Example 5 with ErrorCode

use of com.facebook.presto.spi.ErrorCode in project presto by prestodb.

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 PrestoTransportException) {
        remoteHost = ((PrestoTransportException) 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()), Lists.transform(asList(throwable.getStackTrace()), toStringFunction()), getErrorLocation(throwable), errorCode, remoteHost);
}
Also used : ErrorCode(com.facebook.presto.spi.ErrorCode) StandardErrorCode(com.facebook.presto.spi.StandardErrorCode) HostAddress(com.facebook.presto.spi.HostAddress) PrestoTransportException(com.facebook.presto.spi.PrestoTransportException) Failure(com.facebook.presto.execution.Failure) ExecutionFailureInfo(com.facebook.presto.execution.ExecutionFailureInfo)

Aggregations

ErrorCode (com.facebook.presto.spi.ErrorCode)7 PrestoException (com.facebook.presto.spi.PrestoException)2 Logger (com.facebook.airlift.log.Logger)1 Session (com.facebook.presto.Session)1 FailureInfo (com.facebook.presto.client.FailureInfo)1 QueryError (com.facebook.presto.client.QueryError)1 Type (com.facebook.presto.common.type.Type)1 EMPTY_STAGE_STATS (com.facebook.presto.execution.BasicStageExecutionStats.EMPTY_STAGE_STATS)1 ExecutionFailureInfo (com.facebook.presto.execution.ExecutionFailureInfo)1 Failure (com.facebook.presto.execution.Failure)1 QueryOutputInfo (com.facebook.presto.execution.QueryExecution.QueryOutputInfo)1 QueryState (com.facebook.presto.execution.QueryState)1 DISPATCHING (com.facebook.presto.execution.QueryState.DISPATCHING)1 FINISHED (com.facebook.presto.execution.QueryState.FINISHED)1 FINISHING (com.facebook.presto.execution.QueryState.FINISHING)1 PLANNING (com.facebook.presto.execution.QueryState.PLANNING)1 QUEUED (com.facebook.presto.execution.QueryState.QUEUED)1 RUNNING (com.facebook.presto.execution.QueryState.RUNNING)1 STARTING (com.facebook.presto.execution.QueryState.STARTING)1 TERMINAL_QUERY_STATES (com.facebook.presto.execution.QueryState.TERMINAL_QUERY_STATES)1