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