use of com.facebook.presto.execution.ExecutionFailureInfo in project presto by prestodb.
the class PrestoSparkQueryExecutionFactory method createQueryInfo.
private static QueryInfo createQueryInfo(Session session, String query, QueryState queryState, Optional<PlanAndMore> planAndMore, Optional<String> sparkQueueName, Optional<ExecutionFailureInfo> failureInfo, QueryStateTimer queryStateTimer, Optional<StageInfo> rootStage, WarningCollector warningCollector) {
checkArgument(failureInfo.isPresent() || queryState != FAILED, "unexpected query state: %s", queryState);
int peakRunningTasks = 0;
long peakUserMemoryReservationInBytes = 0;
long peakTotalMemoryReservationInBytes = 0;
long peakTaskUserMemoryInBytes = 0;
long peakTaskTotalMemoryInBytes = 0;
long peakNodeTotalMemoryInBytes = 0;
for (StageInfo stageInfo : getAllStages(rootStage)) {
StageExecutionInfo stageExecutionInfo = stageInfo.getLatestAttemptExecutionInfo();
for (TaskInfo taskInfo : stageExecutionInfo.getTasks()) {
// there's no way to know how many tasks were running in parallel in Spark
// for now let's assume that all the tasks were running in parallel
peakRunningTasks++;
long taskPeakUserMemoryInBytes = taskInfo.getStats().getPeakUserMemoryInBytes();
long taskPeakTotalMemoryInBytes = taskInfo.getStats().getPeakTotalMemoryInBytes();
peakUserMemoryReservationInBytes += taskPeakUserMemoryInBytes;
peakTotalMemoryReservationInBytes += taskPeakTotalMemoryInBytes;
peakTaskUserMemoryInBytes = max(peakTaskUserMemoryInBytes, taskPeakUserMemoryInBytes);
peakTaskTotalMemoryInBytes = max(peakTaskTotalMemoryInBytes, taskPeakTotalMemoryInBytes);
peakNodeTotalMemoryInBytes = max(taskInfo.getStats().getPeakNodeTotalMemoryInBytes(), peakNodeTotalMemoryInBytes);
}
}
QueryStats queryStats = QueryStats.create(queryStateTimer, rootStage, peakRunningTasks, succinctBytes(peakUserMemoryReservationInBytes), succinctBytes(peakTotalMemoryReservationInBytes), succinctBytes(peakTaskUserMemoryInBytes), succinctBytes(peakTaskTotalMemoryInBytes), succinctBytes(peakNodeTotalMemoryInBytes), session.getRuntimeStats());
return new QueryInfo(session.getQueryId(), session.toSessionRepresentation(), queryState, new MemoryPoolId("spark-memory-pool"), queryStats.isScheduled(), URI.create("http://fake.invalid/query/" + session.getQueryId()), planAndMore.map(PlanAndMore::getFieldNames).orElse(ImmutableList.of()), query, Optional.empty(), Optional.empty(), queryStats, Optional.empty(), Optional.empty(), ImmutableMap.of(), ImmutableSet.of(), ImmutableMap.of(), ImmutableMap.of(), ImmutableSet.of(), Optional.empty(), false, planAndMore.flatMap(PlanAndMore::getUpdateType).orElse(null), rootStage, failureInfo.orElse(null), failureInfo.map(ExecutionFailureInfo::getErrorCode).orElse(null), warningCollector.getWarnings(), planAndMore.map(PlanAndMore::getInputs).orElse(ImmutableSet.of()), planAndMore.flatMap(PlanAndMore::getOutput), true, sparkQueueName.map(ResourceGroupId::new), planAndMore.flatMap(PlanAndMore::getQueryType), Optional.empty(), Optional.empty(), ImmutableMap.of(), ImmutableSet.of());
}
use of com.facebook.presto.execution.ExecutionFailureInfo in project presto by prestodb.
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 com.facebook.presto.execution.ExecutionFailureInfo in project presto by prestodb.
the class SqlQueryScheduler method addStateChangeListeners.
private void addStateChangeListeners(SectionExecution sectionExecution) {
for (StageExecutionAndScheduler stageExecutionAndScheduler : sectionExecution.getSectionStages()) {
SqlStageExecution stageExecution = stageExecutionAndScheduler.getStageExecution();
if (isRootFragment(stageExecution.getFragment())) {
stageExecution.addStateChangeListener(state -> {
if (state == FINISHED) {
queryStateMachine.transitionToFinishing();
} else if (state == CANCELED) {
// output stage was canceled
queryStateMachine.transitionToCanceled();
}
});
}
stageExecution.addStateChangeListener(state -> {
if (queryStateMachine.isDone()) {
return;
}
if (state == FAILED) {
ExecutionFailureInfo failureInfo = stageExecution.getStageExecutionInfo().getFailureCause().orElseThrow(() -> new VerifyException(format("stage execution failed, but the failure info is missing: %s", stageExecution.getStageExecutionId())));
Exception failureException = failureInfo.toException();
boolean isRootSection = isRootFragment(sectionExecution.getRootStage().getStageExecution().getFragment());
// root section directly streams the results to the user, cannot be retried
if (isRootSection) {
queryStateMachine.transitionToFailed(failureException);
return;
}
if (retriedSections.get() >= maxStageRetries) {
queryStateMachine.transitionToFailed(failureException);
return;
}
if (!RECOVERABLE_ERROR_CODES.contains(failureInfo.getErrorCode())) {
queryStateMachine.transitionToFailed(failureException);
return;
}
try {
if (sectionExecution.abort()) {
retriedSections.incrementAndGet();
nodeManager.refreshNodes();
startScheduling();
}
} catch (Throwable t) {
if (failureException != t) {
failureException.addSuppressed(t);
}
queryStateMachine.transitionToFailed(failureException);
}
} else if (state == FINISHED) {
// checks if there's any new sections available for execution and starts the scheduling if any
startScheduling();
} else if (queryStateMachine.getQueryState() == QueryState.STARTING) {
// if the stage has at least one task, we are running
if (stageExecution.hasTasks()) {
queryStateMachine.transitionToRunning();
}
}
});
stageExecution.addFinalStageInfoListener(status -> queryStateMachine.updateQueryInfo(Optional.of(getStageInfo())));
}
}
use of com.facebook.presto.execution.ExecutionFailureInfo in project presto by prestodb.
the class LocalDispatchQuery method cancel.
@Override
public void cancel() {
if (stateMachine.transitionToCanceled()) {
BasicQueryInfo queryInfo = stateMachine.getBasicQueryInfo(Optional.empty());
ExecutionFailureInfo failureInfo = queryInfo.getFailureInfo();
failureInfo = failureInfo != null ? failureInfo : toFailure(new PrestoException(USER_CANCELED, "Query was canceled"));
queryMonitor.queryImmediateFailureEvent(queryInfo, failureInfo);
}
}
use of com.facebook.presto.execution.ExecutionFailureInfo in project presto by prestodb.
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().getWaitingForPrerequisitesTime(), queryInfo.getQueryStats().getQueuedTime());
}
if (dispatched) {
return DispatchInfo.dispatched(new LocalCoordinatorLocation(), queryInfo.getQueryStats().getElapsedTime(), queryInfo.getQueryStats().getWaitingForPrerequisitesTime(), queryInfo.getQueryStats().getQueuedTime());
}
if (queryInfo.getState() == QUEUED) {
return DispatchInfo.queued(queryInfo.getQueryStats().getElapsedTime(), queryInfo.getQueryStats().getWaitingForPrerequisitesTime(), queryInfo.getQueryStats().getQueuedTime());
}
return DispatchInfo.waitingForPrerequisites(queryInfo.getQueryStats().getElapsedTime(), queryInfo.getQueryStats().getWaitingForPrerequisitesTime());
}
Aggregations