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