Search in sources :

Example 1 with SqlQueryScheduler

use of com.facebook.presto.execution.scheduler.SqlQueryScheduler in project presto by prestodb.

the class SqlQueryExecution method planDistribution.

private void planDistribution(PlanRoot plan) {
    // time distribution planning
    long distributedPlanningStart = System.nanoTime();
    // plan the execution on the active nodes
    DistributedExecutionPlanner distributedPlanner = new DistributedExecutionPlanner(splitManager);
    StageExecutionPlan outputStageExecutionPlan = distributedPlanner.plan(plan.getRoot(), stateMachine.getSession());
    stateMachine.recordDistributedPlanningTime(distributedPlanningStart);
    // ensure split sources are closed
    stateMachine.addStateChangeListener(state -> {
        if (state.isDone()) {
            closeSplitSources(outputStageExecutionPlan);
        }
    });
    // if query was canceled, skip creating scheduler
    if (stateMachine.isDone()) {
        return;
    }
    // record field names
    stateMachine.setOutputFieldNames(outputStageExecutionPlan.getFieldNames());
    PartitioningHandle partitioningHandle = plan.getRoot().getFragment().getPartitioningScheme().getPartitioning().getHandle();
    OutputBuffers rootOutputBuffers = createInitialEmptyOutputBuffers(partitioningHandle).withBuffer(OUTPUT_BUFFER_ID, BROADCAST_PARTITION_ID).withNoMoreBufferIds();
    // build the stage execution objects (this doesn't schedule execution)
    SqlQueryScheduler scheduler = new SqlQueryScheduler(stateMachine, locationFactory, outputStageExecutionPlan, nodePartitioningManager, nodeScheduler, remoteTaskFactory, stateMachine.getSession(), plan.isSummarizeTaskInfos(), scheduleSplitBatchSize, queryExecutor, rootOutputBuffers, nodeTaskMap, executionPolicy, schedulerStats);
    queryScheduler.set(scheduler);
    // directly since the callback may have already fired
    if (stateMachine.isDone()) {
        scheduler.abort();
        queryScheduler.set(null);
    }
}
Also used : OutputBuffers(com.facebook.presto.OutputBuffers) OutputBuffers.createInitialEmptyOutputBuffers(com.facebook.presto.OutputBuffers.createInitialEmptyOutputBuffers) StageExecutionPlan(com.facebook.presto.sql.planner.StageExecutionPlan) SqlQueryScheduler(com.facebook.presto.execution.scheduler.SqlQueryScheduler) PartitioningHandle(com.facebook.presto.sql.planner.PartitioningHandle) DistributedExecutionPlanner(com.facebook.presto.sql.planner.DistributedExecutionPlanner)

Example 2 with SqlQueryScheduler

use of com.facebook.presto.execution.scheduler.SqlQueryScheduler in project presto by prestodb.

the class SqlQueryExecution method getTotalMemoryReservation.

@Override
public long getTotalMemoryReservation() {
    // acquire reference to outputStage before checking finalQueryInfo, because
    // state change listener sets finalQueryInfo and then clears outputStage when
    // the query finishes.
    SqlQueryScheduler scheduler = queryScheduler.get();
    Optional<QueryInfo> finalQueryInfo = stateMachine.getFinalQueryInfo();
    if (finalQueryInfo.isPresent()) {
        return finalQueryInfo.get().getQueryStats().getTotalMemoryReservation().toBytes();
    }
    if (scheduler == null) {
        return 0;
    }
    return scheduler.getTotalMemoryReservation();
}
Also used : SqlQueryScheduler(com.facebook.presto.execution.scheduler.SqlQueryScheduler)

Example 3 with SqlQueryScheduler

use of com.facebook.presto.execution.scheduler.SqlQueryScheduler 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)

Example 4 with SqlQueryScheduler

use of com.facebook.presto.execution.scheduler.SqlQueryScheduler 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 5 with SqlQueryScheduler

use of com.facebook.presto.execution.scheduler.SqlQueryScheduler in project presto by prestodb.

the class SqlQueryExecution method getTotalCpuTime.

@Override
public Duration getTotalCpuTime() {
    SqlQueryScheduler scheduler = queryScheduler.get();
    Optional<QueryInfo> finalQueryInfo = stateMachine.getFinalQueryInfo();
    if (finalQueryInfo.isPresent()) {
        return finalQueryInfo.get().getQueryStats().getTotalCpuTime();
    }
    if (scheduler == null) {
        return new Duration(0, SECONDS);
    }
    return scheduler.getTotalCpuTime();
}
Also used : SqlQueryScheduler(com.facebook.presto.execution.scheduler.SqlQueryScheduler) Duration(io.airlift.units.Duration)

Aggregations

SqlQueryScheduler (com.facebook.presto.execution.scheduler.SqlQueryScheduler)5 SetThreadName (io.airlift.concurrent.SetThreadName)2 OutputBuffers (com.facebook.presto.OutputBuffers)1 OutputBuffers.createInitialEmptyOutputBuffers (com.facebook.presto.OutputBuffers.createInitialEmptyOutputBuffers)1 DistributedExecutionPlanner (com.facebook.presto.sql.planner.DistributedExecutionPlanner)1 PartitioningHandle (com.facebook.presto.sql.planner.PartitioningHandle)1 StageExecutionPlan (com.facebook.presto.sql.planner.StageExecutionPlan)1 Duration (io.airlift.units.Duration)1