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);
}
}
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();
}
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);
}
}
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);
}
}
}
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();
}
Aggregations