Search in sources :

Example 1 with ErrorCode

use of io.prestosql.spi.ErrorCode in project hetu-core by openlookeng.

the class TestStateUpdater method createBasicQueryInfo.

private BasicQueryInfo createBasicQueryInfo() {
    QueryInfo queryInfo = Mockito.mock(QueryInfo.class);
    when(queryInfo.getQueryStats()).then(new Returns(Mockito.mock(QueryStats.class)));
    Duration mockInterval = new Duration(MINIMUM_UPDATE_INTERVAL, MILLISECONDS);
    when(queryInfo.getQueryStats().getQueuedTime()).then(new Returns(mockInterval));
    when(queryInfo.getQueryStats().getElapsedTime()).then(new Returns(mockInterval));
    when(queryInfo.getQueryStats().getExecutionTime()).then(new Returns(mockInterval));
    when(queryInfo.getQueryStats().getRawInputDataSize()).then(new Returns(Mockito.mock(DataSize.class)));
    String mockQueryId = MOCK_QUERY_ID;
    QueryId queryId = new QueryId(mockQueryId);
    when(queryInfo.getQueryId()).then(new Returns(queryId));
    SessionRepresentation sessionRepresentation = TEST_SESSION.toSessionRepresentation();
    when(queryInfo.getSession()).then(new Returns(sessionRepresentation));
    ResourceGroupId resourceGroupId = new ResourceGroupId(GLOBAL_RESOURCE_ID);
    Optional<ResourceGroupId> optionalResourceGroupId = Optional.of(resourceGroupId);
    when(queryInfo.getResourceGroupId()).then(new Returns(optionalResourceGroupId));
    when(queryInfo.getState()).then(new Returns(QueryState.FINISHED));
    URI mockURI = URI.create(URI_LOCALHOST);
    when(queryInfo.getSelf()).then(new Returns(mockURI));
    String mockQuery = QUERY_STRING;
    when(queryInfo.getQuery()).then(new Returns(mockQuery));
    Optional<String> preparedQuery = Optional.of(PREPARED_QUERY_MOCK_DATA);
    when(queryInfo.getPreparedQuery()).then(new Returns(preparedQuery));
    ErrorCode errorCode = new ErrorCode(ERROR_CODE_VALUE_INDEX_TIME_NO_INVOCATION, ERROR_CODE_TEST, USER_ERROR);
    when(queryInfo.getErrorCode()).then(new Returns(errorCode));
    Set<BlockedReason> setBlockedReason = new HashSet<>();
    setBlockedReason.add(BlockedReason.WAITING_FOR_MEMORY);
    when(queryInfo.getQueryStats().getBlockedReasons()).then(new Returns(setBlockedReason));
    when(queryInfo.getQueryStats().getProgressPercentage()).then(new Returns(OptionalDouble.empty()));
    BasicQueryInfo basicQueryInfo = new BasicQueryInfo(queryInfo);
    return basicQueryInfo;
}
Also used : ResourceGroupId(io.prestosql.spi.resourcegroups.ResourceGroupId) BlockedReason(io.prestosql.operator.BlockedReason) QueryId(io.prestosql.spi.QueryId) BasicQueryInfo(io.prestosql.server.BasicQueryInfo) Duration(io.airlift.units.Duration) QueryInfo(io.prestosql.execution.QueryInfo) BasicQueryInfo(io.prestosql.server.BasicQueryInfo) URI(java.net.URI) Returns(org.mockito.internal.stubbing.answers.Returns) ErrorCode(io.prestosql.spi.ErrorCode) SessionRepresentation(io.prestosql.SessionRepresentation) HashSet(java.util.HashSet)

Example 2 with ErrorCode

use of io.prestosql.spi.ErrorCode in project hetu-core by openlookeng.

the class TestStateUpdater method mockDispatchQueryData.

private DispatchQuery mockDispatchQueryData(boolean userError) {
    DispatchQuery dispatchQuery = Mockito.mock(LocalDispatchQuery.class);
    BasicQueryInfo basicQueryInfo = createBasicQueryInfo();
    when(dispatchQuery.getBasicQueryInfo()).then(new Returns(basicQueryInfo));
    when(dispatchQuery.getSession()).then(new Returns(TEST_SESSION));
    ErrorCode errorCode;
    if (!userError) {
        errorCode = CLUSTER_OUT_OF_MEMORY.toErrorCode();
    } else {
        errorCode = new ErrorCode(ERROR_CODE_VALUE_INDEX_TIME_NO_INVOCATION, ERROR_CODE_TEST, USER_ERROR);
    }
    Optional<ErrorCode> optionalErrorCode = Optional.of(errorCode);
    when(dispatchQuery.getErrorCode()).then(new Returns(optionalErrorCode));
    DataSize userDataSize = new DataSize(USER_DATA_SIZE, DataSize.Unit.BYTE);
    DataSize totalDataSize = new DataSize(TOTAL_DATA_SIZE, DataSize.Unit.BYTE);
    when(dispatchQuery.getUserMemoryReservation()).then(new Returns(userDataSize));
    when(dispatchQuery.getTotalMemoryReservation()).then(new Returns(totalDataSize));
    when(dispatchQuery.getTotalCpuTime()).then(new Returns(new Duration(ERROR_CODE_VALUE_INDEX_TIME_NO_INVOCATION, MILLISECONDS)));
    when(dispatchQuery.getExecutionStartTime()).then(new Returns(Optional.of(new DateTime(DateTimeZone.UTC))));
    return dispatchQuery;
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) DispatchQuery(io.prestosql.dispatcher.DispatchQuery) LocalDispatchQuery(io.prestosql.dispatcher.LocalDispatchQuery) BasicQueryInfo(io.prestosql.server.BasicQueryInfo) DataSize(io.airlift.units.DataSize) Duration(io.airlift.units.Duration) ErrorCode(io.prestosql.spi.ErrorCode) DateTime(org.joda.time.DateTime)

Example 3 with ErrorCode

use of io.prestosql.spi.ErrorCode in project hetu-core by openlookeng.

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);
    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 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.prestosql.server.HttpRemoteTaskFactory) RemoteTask(io.prestosql.execution.RemoteTask) ErrorCode(io.prestosql.spi.ErrorCode)

Example 4 with ErrorCode

use of io.prestosql.spi.ErrorCode 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 5 with ErrorCode

use of io.prestosql.spi.ErrorCode in project hetu-core by openlookeng.

the class QueryStateMachine method getQueryInfo.

@VisibleForTesting
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 localFailureCause = null;
    ErrorCode errorCode = null;
    if (state == FAILED) {
        localFailureCause = this.failureCause.get();
        if (localFailureCause != null) {
            errorCode = localFailureCause.getErrorCode();
        }
    }
    boolean completeInfo = getAllStages(rootStage).stream().allMatch(StageInfo::isCompleteInfo);
    boolean isScheduled = isScheduled(rootStage);
    return new QueryInfo(queryId, session.toSessionRepresentation(), state, memoryPool.get().getId(), isScheduled, self, outputManager.getQueryOutputInfo().map(QueryOutputInfo::getColumnNames).orElse(ImmutableList.of()), query, preparedQuery, getQueryStats(rootStage), Optional.ofNullable(setCatalog.get()), Optional.ofNullable(setSchema.get()), Optional.ofNullable(setPath.get()), setSessionProperties, resetSessionProperties, setRoles, addedPreparedStatements, deallocatedPreparedStatements, Optional.ofNullable(startedTransactionId.get()), clearTransactionId.get(), updateType.get(), rootStage, localFailureCause, errorCode, warningCollector.getWarnings(), inputs.get(), output.get(), completeInfo, Optional.of(resourceGroup), isRunningAsync.get());
}
Also used : QueryOutputInfo(io.prestosql.execution.QueryExecution.QueryOutputInfo) ErrorCode(io.prestosql.spi.ErrorCode) BasicQueryInfo(io.prestosql.server.BasicQueryInfo) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

ErrorCode (io.prestosql.spi.ErrorCode)7 BasicQueryInfo (io.prestosql.server.BasicQueryInfo)4 Duration (io.airlift.units.Duration)2 ExecutionFailureInfo (io.prestosql.execution.ExecutionFailureInfo)2 SemanticErrorCode (io.prestosql.sql.analyzer.SemanticErrorCode)2 Returns (org.mockito.internal.stubbing.answers.Returns)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 DataSize (io.airlift.units.DataSize)1 SessionRepresentation (io.prestosql.SessionRepresentation)1 FailureInfo (io.prestosql.client.FailureInfo)1 QueryError (io.prestosql.client.QueryError)1 DispatchQuery (io.prestosql.dispatcher.DispatchQuery)1 LocalDispatchQuery (io.prestosql.dispatcher.LocalDispatchQuery)1 Failure (io.prestosql.execution.Failure)1 QueryOutputInfo (io.prestosql.execution.QueryExecution.QueryOutputInfo)1 QueryInfo (io.prestosql.execution.QueryInfo)1 QueryState (io.prestosql.execution.QueryState)1 RemoteTask (io.prestosql.execution.RemoteTask)1 BlockedReason (io.prestosql.operator.BlockedReason)1 BasicQueryStats (io.prestosql.server.BasicQueryStats)1