Search in sources :

Example 6 with SetThreadName

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

the class SqlTaskExecution method createSqlTaskExecution.

static SqlTaskExecution createSqlTaskExecution(TaskStateMachine taskStateMachine, TaskContext taskContext, OutputBuffer outputBuffer, List<TaskSource> sources, LocalExecutionPlan localExecutionPlan, TaskExecutor taskExecutor, Executor notificationExecutor, SplitMonitor queryMonitor) {
    SqlTaskExecution task = new SqlTaskExecution(taskStateMachine, taskContext, outputBuffer, localExecutionPlan, taskExecutor, queryMonitor, notificationExecutor);
    try (SetThreadName ignored = new SetThreadName("Task-%s", task.getTaskId())) {
        // The scheduleDriversForTaskLifeCycle method calls enqueueDriverSplitRunner, which registers a callback with access to this object.
        // The call back is accessed from another thread, so this code can not be placed in the constructor.
        task.scheduleDriversForTaskLifeCycle();
        task.addSources(sources);
        return task;
    }
}
Also used : SetThreadName(com.facebook.airlift.concurrent.SetThreadName)

Example 7 with SetThreadName

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

the class SqlTaskExecution 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
        status.incrementRemainingDriver(splitRunner.getLifespan());
        Futures.addCallback(finishedFuture, new FutureCallback<Object>() {

            @Override
            public void onSuccess(Object result) {
                try (SetThreadName ignored = new SetThreadName("Task-%s", taskId)) {
                    // record driver is finished
                    status.decrementRemainingDriver(splitRunner.getLifespan());
                    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
                    status.decrementRemainingDriver(splitRunner.getLifespan());
                    // 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)

Example 8 with SetThreadName

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

the class SqlTaskExecution method addSources.

public void addSources(List<TaskSource> sources) {
    requireNonNull(sources, "sources is null");
    checkState(!Thread.holdsLock(this), "Can not add sources while holding a lock on the %s", getClass().getSimpleName());
    try (SetThreadName ignored = new SetThreadName("Task-%s", taskId)) {
        // update our record of sources and schedule drivers for new partitioned splits
        Map<PlanNodeId, TaskSource> updatedRemoteSources = updateSources(sources);
        // the unpartitioned splits
        for (WeakReference<Driver> driverReference : drivers) {
            Driver driver = driverReference.get();
            // the driver can be GCed due to a failure or a limit
            if (driver == null) {
                // remove the weak reference from the list to avoid a memory leak
                // NOTE: this is a concurrent safe operation on a CopyOnWriteArrayList
                drivers.remove(driverReference);
                continue;
            }
            Optional<PlanNodeId> sourceId = driver.getSourceId();
            if (!sourceId.isPresent()) {
                continue;
            }
            TaskSource sourceUpdate = updatedRemoteSources.get(sourceId.get());
            if (sourceUpdate == null) {
                continue;
            }
            driver.updateSource(sourceUpdate);
        }
        // we may have transitioned to no more splits, so check for completion
        checkTaskCompletion();
    }
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) SetThreadName(com.facebook.airlift.concurrent.SetThreadName) Driver(com.facebook.presto.operator.Driver)

Example 9 with SetThreadName

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

the class SqlTaskExecutionFactory method create.

public SqlTaskExecution create(Session session, QueryContext queryContext, TaskStateMachine taskStateMachine, OutputBuffer outputBuffer, TaskExchangeClientManager taskExchangeClientManager, PlanFragment fragment, List<TaskSource> sources, TableWriteInfo tableWriteInfo) {
    TaskContext taskContext = queryContext.addTaskContext(taskStateMachine, session, // Plan has to be retained only if verbose memory exceeded errors are requested
    isVerboseExceededMemoryLimitErrorsEnabled(session) ? Optional.of(fragment.getRoot()) : Optional.empty(), perOperatorCpuTimerEnabled, cpuTimerEnabled, perOperatorAllocationTrackingEnabled, allocationTrackingEnabled, legacyLifespanCompletionCondition);
    LocalExecutionPlan localExecutionPlan;
    try (SetThreadName ignored = new SetThreadName("Task-%s", taskStateMachine.getTaskId())) {
        try {
            localExecutionPlan = planner.plan(taskContext, fragment.getRoot(), fragment.getPartitioningScheme(), fragment.getStageExecutionDescriptor(), fragment.getTableScanSchedulingOrder(), outputBuffer, new HttpRemoteSourceFactory(blockEncodingSerde, taskExchangeClientManager, orderingCompiler), tableWriteInfo);
        } catch (Throwable e) {
            // planning failed
            taskStateMachine.failed(e);
            throwIfUnchecked(e);
            throw new RuntimeException(e);
        }
    }
    return createSqlTaskExecution(taskStateMachine, taskContext, outputBuffer, sources, localExecutionPlan, taskExecutor, taskNotificationExecutor, splitMonitor);
}
Also used : LocalExecutionPlan(com.facebook.presto.sql.planner.LocalExecutionPlanner.LocalExecutionPlan) TaskContext(com.facebook.presto.operator.TaskContext) SetThreadName(com.facebook.airlift.concurrent.SetThreadName) HttpRemoteSourceFactory(com.facebook.presto.sql.planner.HttpRemoteSourceFactory)

Example 10 with SetThreadName

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

the class SqlQueryExecution method start.

@Override
public void start() {
    try (SetThreadName ignored = new SetThreadName("Query-%s", stateMachine.getQueryId())) {
        try {
            // transition to planning
            if (!stateMachine.transitionToPlanning()) {
                // query already started or finished
                return;
            }
            // analyze query
            PlanRoot plan = analyzeQuery();
            metadata.beginQuery(getSession(), plan.getConnectors());
            // plan distribution of query
            planDistribution(plan);
            // transition to starting
            if (!stateMachine.transitionToStarting()) {
                // query already started or finished
                return;
            }
            // if query is not finished, start the scheduler, otherwise cancel it
            SqlQuerySchedulerInterface scheduler = queryScheduler.get();
            if (!stateMachine.isDone()) {
                scheduler.start();
            }
        } catch (Throwable e) {
            fail(e);
            throwIfInstanceOf(e, Error.class);
        }
    }
}
Also used : SetThreadName(com.facebook.airlift.concurrent.SetThreadName) SqlQuerySchedulerInterface(com.facebook.presto.execution.scheduler.SqlQuerySchedulerInterface)

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