Search in sources :

Example 16 with SetThreadName

use of com.facebook.airlift.concurrent.SetThreadName in project presto by prestodb.

the class PrestoSparkTaskExecution method enqueueDriverSplitRunner.

private synchronized void enqueueDriverSplitRunner(boolean forceRunSplit, List<DriverSplitRunner> runners) {
    // schedule driver to be executed
    List<ListenableFuture<?>> finishedFutures = taskExecutor.enqueueSplits(taskHandle, forceRunSplit, runners);
    checkState(finishedFutures.size() == runners.size(), "Expected %s futures but got %s", runners.size(), finishedFutures.size());
    // when driver completes, update state and fire events
    for (int i = 0; i < finishedFutures.size(); i++) {
        ListenableFuture<?> finishedFuture = finishedFutures.get(i);
        final DriverSplitRunner splitRunner = runners.get(i);
        // record new driver
        remainingDrivers.incrementAndGet();
        Futures.addCallback(finishedFuture, new FutureCallback<Object>() {

            @Override
            public void onSuccess(Object result) {
                try (SetThreadName ignored = new SetThreadName("Task-%s", taskId)) {
                    // record driver is finished
                    remainingDrivers.decrementAndGet();
                    checkTaskCompletion();
                    splitMonitor.splitCompletedEvent(taskId, getDriverStats());
                }
            }

            @Override
            public void onFailure(Throwable cause) {
                try (SetThreadName ignored = new SetThreadName("Task-%s", taskId)) {
                    taskStateMachine.failed(cause);
                    // record driver is finished
                    remainingDrivers.decrementAndGet();
                    // fire failed event with cause
                    splitMonitor.splitFailedEvent(taskId, getDriverStats(), cause);
                }
            }

            private DriverStats getDriverStats() {
                DriverContext driverContext = splitRunner.getDriverContext();
                DriverStats driverStats;
                if (driverContext != null) {
                    driverStats = driverContext.getDriverStats();
                } else {
                    // split runner did not start successfully
                    driverStats = new DriverStats();
                }
                return driverStats;
            }
        }, notificationExecutor);
    }
}
Also used : DriverContext(com.facebook.presto.operator.DriverContext) DriverStats(com.facebook.presto.operator.DriverStats) SetThreadName(com.facebook.airlift.concurrent.SetThreadName) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Aggregations

SetThreadName (com.facebook.airlift.concurrent.SetThreadName)16 SqlStageExecution (com.facebook.presto.execution.SqlStageExecution)4 MoreFutures.tryGetFutureValue (com.facebook.airlift.concurrent.MoreFutures.tryGetFutureValue)2 MoreFutures.whenAnyComplete (com.facebook.airlift.concurrent.MoreFutures.whenAnyComplete)2 HttpUriBuilder (com.facebook.airlift.http.client.HttpUriBuilder)2 HttpUriBuilder.uriBuilderFrom (com.facebook.airlift.http.client.HttpUriBuilder.uriBuilderFrom)2 Request (com.facebook.airlift.http.client.Request)2 Logger (com.facebook.airlift.log.Logger)2 TimeStat (com.facebook.airlift.stats.TimeStat)2 Session (com.facebook.presto.Session)2 SystemSessionProperties.getMaxConcurrentMaterializations (com.facebook.presto.SystemSessionProperties.getMaxConcurrentMaterializations)2 SystemSessionProperties.getPartialResultsCompletionRatioThreshold (com.facebook.presto.SystemSessionProperties.getPartialResultsCompletionRatioThreshold)2 SystemSessionProperties.getPartialResultsMaxExecutionTimeMultiplier (com.facebook.presto.SystemSessionProperties.getPartialResultsMaxExecutionTimeMultiplier)2 SystemSessionProperties.isPartialResultsEnabled (com.facebook.presto.SystemSessionProperties.isPartialResultsEnabled)2 SystemSessionProperties.isRuntimeOptimizerEnabled (com.facebook.presto.SystemSessionProperties.isRuntimeOptimizerEnabled)2 BasicStageExecutionStats (com.facebook.presto.execution.BasicStageExecutionStats)2 BasicStageExecutionStats.aggregateBasicStageStats (com.facebook.presto.execution.BasicStageExecutionStats.aggregateBasicStageStats)2 LocationFactory (com.facebook.presto.execution.LocationFactory)2 PartialResultQueryManager (com.facebook.presto.execution.PartialResultQueryManager)2 QueryState (com.facebook.presto.execution.QueryState)2