Search in sources :

Example 6 with SetThreadName

use of io.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
            SqlQueryScheduler scheduler = queryScheduler.get();
            if (!stateMachine.isDone()) {
                scheduler.start();
            }
        } catch (Throwable e) {
            fail(e);
            Throwables.propagateIfInstanceOf(e, Error.class);
        }
    }
}
Also used : SqlQueryScheduler(com.facebook.presto.execution.scheduler.SqlQueryScheduler) SetThreadName(io.airlift.concurrent.SetThreadName)

Example 7 with SetThreadName

use of io.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> updatedUnpartitionedSources = updateSources(sources);
        // the unpartitioned splits
        for (TaskSource source : updatedUnpartitionedSources.values()) {
            // tell all the existing drivers this source is finished
            for (WeakReference<Driver> driverReference : drivers) {
                Driver driver = driverReference.get();
                // the driver can be GCed due to a failure or a limit
                if (driver != null) {
                    driver.updateSource(source);
                } else {
                    // 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);
                }
            }
        }
        // we may have transitioned to no more splits, so check for completion
        checkTaskCompletion();
    }
}
Also used : PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) SetThreadName(io.airlift.concurrent.SetThreadName) Driver(com.facebook.presto.operator.Driver) TaskSource(com.facebook.presto.TaskSource)

Example 8 with SetThreadName

use of io.airlift.concurrent.SetThreadName in project presto by prestodb.

the class SqlTaskExecution method enqueueDrivers.

private synchronized void enqueueDrivers(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());
    // record new driver
    remainingDrivers.addAndGet(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);
        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();
                    queryMonitor.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
                    queryMonitor.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(io.airlift.concurrent.SetThreadName) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Example 9 with SetThreadName

use of io.airlift.concurrent.SetThreadName in project presto by prestodb.

the class ContinuousTaskStatusFetcher method success.

@Override
public void success(TaskStatus value) {
    try (SetThreadName ignored = new SetThreadName("ContinuousTaskStatusFetcher-%s", taskId)) {
        updateStats(currentRequestStartNanos.get());
        try {
            updateTaskStatus(value);
            errorTracker.requestSucceeded();
        } finally {
            scheduleNextRequest();
        }
    }
}
Also used : SetThreadName(io.airlift.concurrent.SetThreadName)

Example 10 with SetThreadName

use of io.airlift.concurrent.SetThreadName in project presto by prestodb.

the class ContinuousTaskStatusFetcher method fatal.

@Override
public void fatal(Throwable cause) {
    try (SetThreadName ignored = new SetThreadName("ContinuousTaskStatusFetcher-%s", taskId)) {
        updateStats(currentRequestStartNanos.get());
        onFail.accept(cause);
    }
}
Also used : SetThreadName(io.airlift.concurrent.SetThreadName)

Aggregations

SetThreadName (io.airlift.concurrent.SetThreadName)13 SqlStageExecution (com.facebook.presto.execution.SqlStageExecution)2 SqlQueryScheduler (com.facebook.presto.execution.scheduler.SqlQueryScheduler)2 TaskUpdateRequest (com.facebook.presto.server.TaskUpdateRequest)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 HttpUriBuilder (io.airlift.http.client.HttpUriBuilder)2 Request (io.airlift.http.client.Request)2 TaskSource (com.facebook.presto.TaskSource)1 StageId (com.facebook.presto.execution.StageId)1 StageState (com.facebook.presto.execution.StageState)1 TaskStatus (com.facebook.presto.execution.TaskStatus)1 Driver (com.facebook.presto.operator.Driver)1 DriverContext (com.facebook.presto.operator.DriverContext)1 DriverStats (com.facebook.presto.operator.DriverStats)1 PrestoException (com.facebook.presto.spi.PrestoException)1 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)1 TimeStat (io.airlift.stats.TimeStat)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1