Search in sources :

Example 1 with ExecutionFailureInfo

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());
}
Also used : TaskInfo(com.facebook.presto.execution.TaskInfo) SerializedTaskInfo(com.facebook.presto.spark.classloader_interface.SerializedTaskInfo) PlanAndMore(com.facebook.presto.spark.planner.PrestoSparkQueryPlanner.PlanAndMore) QueryStats(com.facebook.presto.execution.QueryStats) StageInfo(com.facebook.presto.execution.StageInfo) StageExecutionInfo(com.facebook.presto.execution.StageExecutionInfo) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) QueryInfo(com.facebook.presto.execution.QueryInfo) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) ExecutionFailureInfo(com.facebook.presto.execution.ExecutionFailureInfo)

Example 2 with ExecutionFailureInfo

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());
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) ExecutionFailureInfo(com.facebook.presto.execution.ExecutionFailureInfo) Test(org.testng.annotations.Test)

Example 3 with ExecutionFailureInfo

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())));
    }
}
Also used : VerifyException(com.google.common.base.VerifyException) SqlStageExecution(com.facebook.presto.execution.SqlStageExecution) PrestoException(com.facebook.presto.spi.PrestoException) VerifyException(com.google.common.base.VerifyException) ExecutionFailureInfo(com.facebook.presto.execution.ExecutionFailureInfo)

Example 4 with ExecutionFailureInfo

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);
    }
}
Also used : BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) PrestoException(com.facebook.presto.spi.PrestoException) ExecutionFailureInfo(com.facebook.presto.execution.ExecutionFailureInfo)

Example 5 with ExecutionFailureInfo

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());
}
Also used : BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) PrestoException(com.facebook.presto.spi.PrestoException) ExecutionFailureInfo(com.facebook.presto.execution.ExecutionFailureInfo)

Aggregations

ExecutionFailureInfo (com.facebook.presto.execution.ExecutionFailureInfo)10 PrestoException (com.facebook.presto.spi.PrestoException)5 BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)4 Test (org.testng.annotations.Test)2 Failure (com.facebook.presto.execution.Failure)1 QueryInfo (com.facebook.presto.execution.QueryInfo)1 QueryStats (com.facebook.presto.execution.QueryStats)1 SqlStageExecution (com.facebook.presto.execution.SqlStageExecution)1 StageExecutionInfo (com.facebook.presto.execution.StageExecutionInfo)1 StageInfo (com.facebook.presto.execution.StageInfo)1 TaskInfo (com.facebook.presto.execution.TaskInfo)1 PrestoSparkExecutionException (com.facebook.presto.spark.classloader_interface.PrestoSparkExecutionException)1 PrestoSparkNonRetryableExecutionException (com.facebook.presto.spark.classloader_interface.PrestoSparkNonRetryableExecutionException)1 PrestoSparkRetryableExecutionException (com.facebook.presto.spark.classloader_interface.PrestoSparkRetryableExecutionException)1 SerializedTaskInfo (com.facebook.presto.spark.classloader_interface.SerializedTaskInfo)1 PlanAndMore (com.facebook.presto.spark.planner.PrestoSparkQueryPlanner.PlanAndMore)1 ErrorCode (com.facebook.presto.spi.ErrorCode)1 HostAddress (com.facebook.presto.spi.HostAddress)1 PrestoTransportException (com.facebook.presto.spi.PrestoTransportException)1 StandardErrorCode (com.facebook.presto.spi.StandardErrorCode)1