Search in sources :

Example 1 with ExecutionFailureInfo

use of io.prestosql.execution.ExecutionFailureInfo in project hetu-core by openlookeng.

the class Failures method toFailure.

private static ExecutionFailureInfo toFailure(Throwable throwable, Set<Throwable> seenFailures) {
    if (throwable == null) {
        return null;
    }
    String type;
    HostAddress remoteHost = null;
    SemanticErrorCode semanticErrorCode = 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 (throwable instanceof SemanticException) {
        semanticErrorCode = ((SemanticException) throwable).getCode();
    }
    if (seenFailures.contains(throwable)) {
        return new ExecutionFailureInfo(type, "[cyclic] " + throwable.getMessage(), null, ImmutableList.of(), ImmutableList.of(), null, GENERIC_INTERNAL_ERROR.toErrorCode(), Optional.ofNullable(semanticErrorCode), 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, Optional.ofNullable(semanticErrorCode), remoteHost);
}
Also used : SemanticErrorCode(io.prestosql.sql.analyzer.SemanticErrorCode) ErrorCode(io.prestosql.spi.ErrorCode) StandardErrorCode(io.prestosql.spi.StandardErrorCode) HostAddress(io.prestosql.spi.HostAddress) SemanticErrorCode(io.prestosql.sql.analyzer.SemanticErrorCode) PrestoTransportException(io.prestosql.spi.PrestoTransportException) Failure(io.prestosql.execution.Failure) SemanticException(io.prestosql.sql.analyzer.SemanticException) ExecutionFailureInfo(io.prestosql.execution.ExecutionFailureInfo)

Example 2 with ExecutionFailureInfo

use of io.prestosql.execution.ExecutionFailureInfo in project hetu-core by openlookeng.

the class FailedDispatchQueryFactory method createFailedDispatchQuery.

public FailedDispatchQuery createFailedDispatchQuery(Session session, String query, Optional<ResourceGroupId> resourceGroup, Throwable throwable) {
    ExecutionFailureInfo failure = toFailure(throwable);
    FailedDispatchQuery failedDispatchQuery = new FailedDispatchQuery(session, query, locationFactory.createQueryLocation(session.getQueryId()), resourceGroup, failure, executor);
    BasicQueryInfo queryInfo = failedDispatchQuery.getBasicQueryInfo();
    queryMonitor.queryCreatedEvent(queryInfo);
    queryMonitor.queryImmediateFailureEvent(queryInfo, failure);
    return failedDispatchQuery;
}
Also used : BasicQueryInfo(io.prestosql.server.BasicQueryInfo) ExecutionFailureInfo(io.prestosql.execution.ExecutionFailureInfo)

Example 3 with ExecutionFailureInfo

use of io.prestosql.execution.ExecutionFailureInfo in project hetu-core by openlookeng.

the class LocalDispatchQuery method getDispatchInfo.

@Override
public DispatchInfo getDispatchInfo() {
    // observe submitted before getting the state, to ensure a failed query stat is visible
    boolean dispatched = submitted.isDone();
    BasicQueryInfo queryInfo = stateMachine.getBasicQueryInfo(Optional.empty());
    if (queryInfo.getState() == FAILED) {
        ExecutionFailureInfo failureInfo = stateMachine.getFailureInfo().orElseGet(() -> toFailure(new PrestoException(GENERIC_INTERNAL_ERROR, "Query failed for an unknown reason")));
        return DispatchInfo.failed(failureInfo, queryInfo.getQueryStats().getElapsedTime(), queryInfo.getQueryStats().getQueuedTime());
    }
    if (dispatched) {
        return DispatchInfo.dispatched(new LocalCoordinatorLocation(), queryInfo.getQueryStats().getElapsedTime(), queryInfo.getQueryStats().getQueuedTime());
    }
    return DispatchInfo.queued(queryInfo.getQueryStats().getElapsedTime(), queryInfo.getQueryStats().getQueuedTime());
}
Also used : BasicQueryInfo(io.prestosql.server.BasicQueryInfo) PrestoException(io.prestosql.spi.PrestoException) ExecutionFailureInfo(io.prestosql.execution.ExecutionFailureInfo)

Example 4 with ExecutionFailureInfo

use of io.prestosql.execution.ExecutionFailureInfo in project hetu-core by openlookeng.

the class TestFailures method testToFailureLoop.

@Test
public void testToFailureLoop() {
    Throwable exception1 = new PrestoException(TOO_MANY_REQUESTS_FAILED, "fake exception 1");
    Throwable exception2 = new RuntimeException("fake exception 2", exception1);
    exception1.addSuppressed(exception2);
    // add exception 1 --> add suppress (exception 2) --> add cause (exception 1)
    ExecutionFailureInfo failure = toFailure(exception1);
    assertEquals(failure.getMessage(), "fake exception 1");
    assertNull(failure.getCause());
    assertEquals(failure.getSuppressed().size(), 1);
    assertEquals(failure.getSuppressed().get(0).getMessage(), "fake exception 2");
    assertEquals(failure.getErrorCode(), TOO_MANY_REQUESTS_FAILED.toErrorCode());
    // add exception 2 --> add cause (exception 2) --> add suppress (exception 1)
    failure = toFailure(exception2);
    assertEquals(failure.getMessage(), "fake exception 2");
    assertNotNull(failure.getCause());
    assertEquals(failure.getCause().getMessage(), "fake exception 1");
    assertEquals(failure.getSuppressed().size(), 0);
    assertEquals(failure.getErrorCode(), TOO_MANY_REQUESTS_FAILED.toErrorCode());
    // add exception 1 --> add suppress (exception 2) --> add suppress (exception 1)
    exception1 = new PrestoException(TOO_MANY_REQUESTS_FAILED, "fake exception 1");
    exception2 = new RuntimeException("fake exception 2");
    exception1.addSuppressed(exception2);
    exception2.addSuppressed(exception1);
    failure = toFailure(exception1);
    assertEquals(failure.getMessage(), "fake exception 1");
    assertNull(failure.getCause());
    assertEquals(failure.getSuppressed().size(), 1);
    assertEquals(failure.getSuppressed().get(0).getMessage(), "fake exception 2");
    assertEquals(failure.getErrorCode(), TOO_MANY_REQUESTS_FAILED.toErrorCode());
    // add exception 2 --> add cause (exception 1) --> add cause (exception 2)
    exception1 = new RuntimeException("fake exception 1");
    exception2 = new RuntimeException("fake exception 2", exception1);
    exception1.initCause(exception2);
    failure = toFailure(exception2);
    assertEquals(failure.getMessage(), "fake exception 2");
    assertNotNull(failure.getCause());
    assertEquals(failure.getCause().getMessage(), "fake exception 1");
    assertEquals(failure.getSuppressed().size(), 0);
    assertEquals(failure.getErrorCode(), GENERIC_INTERNAL_ERROR.toErrorCode());
}
Also used : PrestoException(io.prestosql.spi.PrestoException) ExecutionFailureInfo(io.prestosql.execution.ExecutionFailureInfo) Test(org.testng.annotations.Test)

Example 5 with ExecutionFailureInfo

use of io.prestosql.execution.ExecutionFailureInfo in project hetu-core by openlookeng.

the class Query method toQueryError.

private static QueryError toQueryError(QueryInfo queryInfo) {
    QueryState state = queryInfo.getState();
    if (state != FAILED) {
        return null;
    }
    ExecutionFailureInfo executionFailure;
    if (queryInfo.getFailureInfo() != null) {
        executionFailure = queryInfo.getFailureInfo();
    } 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.toFailureInfoWithoutStack();
    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(), executionFailure.getSemanticErrorCode().map(SemanticErrorCode::name), errorCode.getType().toString(), failure.getErrorLocation(), failure);
}
Also used : FailureInfo(io.prestosql.client.FailureInfo) ExecutionFailureInfo(io.prestosql.execution.ExecutionFailureInfo) QueryState(io.prestosql.execution.QueryState) SemanticErrorCode(io.prestosql.sql.analyzer.SemanticErrorCode) ErrorCode(io.prestosql.spi.ErrorCode) QueryError(io.prestosql.client.QueryError) ExecutionFailureInfo(io.prestosql.execution.ExecutionFailureInfo)

Aggregations

ExecutionFailureInfo (io.prestosql.execution.ExecutionFailureInfo)6 BasicQueryInfo (io.prestosql.server.BasicQueryInfo)2 ErrorCode (io.prestosql.spi.ErrorCode)2 PrestoException (io.prestosql.spi.PrestoException)2 SemanticErrorCode (io.prestosql.sql.analyzer.SemanticErrorCode)2 FailureInfo (io.prestosql.client.FailureInfo)1 QueryError (io.prestosql.client.QueryError)1 Failure (io.prestosql.execution.Failure)1 QueryState (io.prestosql.execution.QueryState)1 TaskStatus (io.prestosql.execution.TaskStatus)1 HostAddress (io.prestosql.spi.HostAddress)1 PrestoTransportException (io.prestosql.spi.PrestoTransportException)1 StandardErrorCode (io.prestosql.spi.StandardErrorCode)1 SemanticException (io.prestosql.sql.analyzer.SemanticException)1 Test (org.testng.annotations.Test)1