Search in sources :

Example 1 with SetThreadName

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

the class SqlQueryScheduler method cancelStage.

public void cancelStage(StageId stageId) {
    try (SetThreadName ignored = new SetThreadName("Query-%s", queryStateMachine.getQueryId())) {
        SqlStageExecution sqlStageExecution = stages.get(stageId);
        SqlStageExecution stage = requireNonNull(sqlStageExecution, () -> format("Stage %s does not exist", stageId));
        stage.cancel();
    }
}
Also used : SetThreadName(io.airlift.concurrent.SetThreadName) SqlStageExecution(com.facebook.presto.execution.SqlStageExecution)

Example 2 with SetThreadName

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

the class SqlQueryScheduler method schedule.

private void schedule() {
    try (SetThreadName ignored = new SetThreadName("Query-%s", queryStateMachine.getQueryId())) {
        Set<StageId> completedStages = new HashSet<>();
        ExecutionSchedule executionSchedule = executionPolicy.createExecutionSchedule(stages.values());
        while (!executionSchedule.isFinished()) {
            List<ListenableFuture<?>> blockedStages = new ArrayList<>();
            for (SqlStageExecution stage : executionSchedule.getStagesToSchedule()) {
                stage.beginScheduling();
                // perform some scheduling work
                ScheduleResult result = stageSchedulers.get(stage.getStageId()).schedule();
                // modify parent and children based on the results of the scheduling
                if (result.isFinished()) {
                    stage.schedulingComplete();
                } else if (!result.getBlocked().isDone()) {
                    blockedStages.add(result.getBlocked());
                }
                stageLinkages.get(stage.getStageId()).processScheduleResults(stage.getState(), result.getNewTasks());
                schedulerStats.getSplitsScheduledPerIteration().add(result.getSplitsScheduled());
                if (result.getBlockedReason().isPresent()) {
                    switch(result.getBlockedReason().get()) {
                        case WAITING_FOR_SOURCE:
                            schedulerStats.getWaitingForSource().update(1);
                            break;
                        case SPLIT_QUEUES_FULL:
                            schedulerStats.getSplitQueuesFull().update(1);
                            break;
                        default:
                            throw new UnsupportedOperationException("Unknown blocked reason: " + result.getBlockedReason().get());
                    }
                }
            }
            // make sure to update stage linkage at least once per loop to catch async state changes (e.g., partial cancel)
            for (SqlStageExecution stage : stages.values()) {
                if (!completedStages.contains(stage.getStageId()) && stage.getState().isDone()) {
                    stageLinkages.get(stage.getStageId()).processScheduleResults(stage.getState(), ImmutableSet.of());
                    completedStages.add(stage.getStageId());
                }
            }
            // wait for a state change and then schedule again
            if (!blockedStages.isEmpty()) {
                try (TimeStat.BlockTimer timer = schedulerStats.getSleepTime().time()) {
                    tryGetFutureValue(whenAnyComplete(blockedStages), 1, SECONDS);
                }
                for (ListenableFuture<?> blockedStage : blockedStages) {
                    blockedStage.cancel(true);
                }
            }
        }
        for (SqlStageExecution stage : stages.values()) {
            StageState state = stage.getState();
            if (state != SCHEDULED && state != RUNNING && !state.isDone()) {
                throw new PrestoException(GENERIC_INTERNAL_ERROR, format("Scheduling is complete, but stage %s is in state %s", stage.getStageId(), state));
            }
        }
    } catch (Throwable t) {
        queryStateMachine.transitionToFailed(t);
        throw Throwables.propagate(t);
    } finally {
        RuntimeException closeError = new RuntimeException();
        for (StageScheduler scheduler : stageSchedulers.values()) {
            try {
                scheduler.close();
            } catch (Throwable t) {
                queryStateMachine.transitionToFailed(t);
                // Self-suppression not permitted
                if (closeError != t) {
                    closeError.addSuppressed(t);
                }
            }
        }
        if (closeError.getSuppressed().length > 0) {
            throw closeError;
        }
    }
}
Also used : StageId(com.facebook.presto.execution.StageId) ArrayList(java.util.ArrayList) TimeStat(io.airlift.stats.TimeStat) PrestoException(com.facebook.presto.spi.PrestoException) SqlStageExecution(com.facebook.presto.execution.SqlStageExecution) StageState(com.facebook.presto.execution.StageState) SetThreadName(io.airlift.concurrent.SetThreadName) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) HashSet(java.util.HashSet)

Example 3 with SetThreadName

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

the class SqlTaskExecution method createSqlTaskExecution.

public static SqlTaskExecution createSqlTaskExecution(TaskStateMachine taskStateMachine, TaskContext taskContext, OutputBuffer outputBuffer, PlanFragment fragment, List<TaskSource> sources, LocalExecutionPlanner planner, TaskExecutor taskExecutor, Executor notificationExecutor, QueryMonitor queryMonitor) {
    SqlTaskExecution task = new SqlTaskExecution(taskStateMachine, taskContext, outputBuffer, fragment, planner, taskExecutor, queryMonitor, notificationExecutor);
    try (SetThreadName ignored = new SetThreadName("Task-%s", task.getTaskId())) {
        task.start();
        task.addSources(sources);
        return task;
    }
}
Also used : SetThreadName(io.airlift.concurrent.SetThreadName)

Example 4 with SetThreadName

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

the class TaskInfoFetcher method success.

@Override
public void success(TaskInfo newValue) {
    try (SetThreadName ignored = new SetThreadName("TaskInfoFetcher-%s", taskId)) {
        lastUpdateNanos.set(System.nanoTime());
        long startNanos;
        synchronized (this) {
            startNanos = this.currentRequestStartNanos.get();
        }
        updateStats(startNanos);
        errorTracker.requestSucceeded();
        updateTaskInfo(newValue);
    }
}
Also used : SetThreadName(io.airlift.concurrent.SetThreadName)

Example 5 with SetThreadName

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

the class SqlQueryExecution method getQueryInfo.

@Override
public QueryInfo getQueryInfo() {
    try (SetThreadName ignored = new SetThreadName("Query-%s", stateMachine.getQueryId())) {
        // acquire reference to scheduler before checking finalQueryInfo, because
        // state change listener sets finalQueryInfo and then clears scheduler when
        // the query finishes.
        SqlQueryScheduler scheduler = queryScheduler.get();
        Optional<QueryInfo> finalQueryInfo = stateMachine.getFinalQueryInfo();
        if (finalQueryInfo.isPresent()) {
            return finalQueryInfo.get();
        }
        return buildQueryInfo(scheduler);
    }
}
Also used : SqlQueryScheduler(com.facebook.presto.execution.scheduler.SqlQueryScheduler) 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