Search in sources :

Example 1 with StageExecutionPlan

use of com.facebook.presto.sql.planner.StageExecutionPlan in project presto by prestodb.

the class SqlQueryScheduler method createStages.

private List<SqlStageExecution> createStages(Optional<SqlStageExecution> parent, AtomicInteger nextStageId, LocationFactory locationFactory, StageExecutionPlan plan, NodeScheduler nodeScheduler, RemoteTaskFactory remoteTaskFactory, Session session, int splitBatchSize, Function<PartitioningHandle, NodePartitionMap> partitioningCache, ExecutorService executor, NodeTaskMap nodeTaskMap, ImmutableMap.Builder<StageId, StageScheduler> stageSchedulers, ImmutableMap.Builder<StageId, StageLinkage> stageLinkages) {
    ImmutableList.Builder<SqlStageExecution> stages = ImmutableList.builder();
    StageId stageId = new StageId(queryStateMachine.getQueryId(), nextStageId.getAndIncrement());
    SqlStageExecution stage = new SqlStageExecution(stageId, locationFactory.createStageLocation(stageId), plan.getFragment(), remoteTaskFactory, session, summarizeTaskInfo, nodeTaskMap, executor, schedulerStats);
    stages.add(stage);
    Optional<int[]> bucketToPartition;
    PartitioningHandle partitioningHandle = plan.getFragment().getPartitioning();
    if (partitioningHandle.equals(SOURCE_DISTRIBUTION)) {
        // nodes are selected dynamically based on the constraints of the splits and the system load
        Entry<PlanNodeId, SplitSource> entry = Iterables.getOnlyElement(plan.getSplitSources().entrySet());
        ConnectorId connectorId = entry.getValue().getConnectorId();
        if (isInternalSystemConnector(connectorId)) {
            connectorId = null;
        }
        NodeSelector nodeSelector = nodeScheduler.createNodeSelector(connectorId);
        SplitPlacementPolicy placementPolicy = new DynamicSplitPlacementPolicy(nodeSelector, stage::getAllTasks);
        stageSchedulers.put(stageId, new SourcePartitionedScheduler(stage, entry.getKey(), entry.getValue(), placementPolicy, splitBatchSize));
        bucketToPartition = Optional.of(new int[1]);
    } else {
        // nodes are pre determined by the nodePartitionMap
        NodePartitionMap nodePartitionMap = partitioningCache.apply(plan.getFragment().getPartitioning());
        Map<PlanNodeId, SplitSource> splitSources = plan.getSplitSources();
        if (!splitSources.isEmpty()) {
            stageSchedulers.put(stageId, new FixedSourcePartitionedScheduler(stage, splitSources, plan.getFragment().getPartitionedSources(), nodePartitionMap, splitBatchSize, nodeScheduler.createNodeSelector(null)));
            bucketToPartition = Optional.of(nodePartitionMap.getBucketToPartition());
        } else {
            Map<Integer, Node> partitionToNode = nodePartitionMap.getPartitionToNode();
            // todo this should asynchronously wait a standard timeout period before failing
            checkCondition(!partitionToNode.isEmpty(), NO_NODES_AVAILABLE, "No worker nodes available");
            stageSchedulers.put(stageId, new FixedCountScheduler(stage, partitionToNode));
            bucketToPartition = Optional.of(nodePartitionMap.getBucketToPartition());
        }
    }
    ImmutableSet.Builder<SqlStageExecution> childStagesBuilder = ImmutableSet.builder();
    for (StageExecutionPlan subStagePlan : plan.getSubStages()) {
        List<SqlStageExecution> subTree = createStages(Optional.of(stage), nextStageId, locationFactory, subStagePlan.withBucketToPartition(bucketToPartition), nodeScheduler, remoteTaskFactory, session, splitBatchSize, partitioningCache, executor, nodeTaskMap, stageSchedulers, stageLinkages);
        stages.addAll(subTree);
        SqlStageExecution childStage = subTree.get(0);
        childStagesBuilder.add(childStage);
    }
    Set<SqlStageExecution> childStages = childStagesBuilder.build();
    stage.addStateChangeListener(newState -> {
        if (newState.isDone()) {
            childStages.forEach(SqlStageExecution::cancel);
        }
    });
    stageLinkages.put(stageId, new StageLinkage(plan.getFragment().getId(), parent, childStages));
    return stages.build();
}
Also used : ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) StageExecutionPlan(com.facebook.presto.sql.planner.StageExecutionPlan) StageId(com.facebook.presto.execution.StageId) Node(com.facebook.presto.spi.Node) SqlStageExecution(com.facebook.presto.execution.SqlStageExecution) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) ImmutableCollectors.toImmutableSet(com.facebook.presto.util.ImmutableCollectors.toImmutableSet) ImmutableSet(com.google.common.collect.ImmutableSet) ConnectorId(com.facebook.presto.connector.ConnectorId) NodePartitionMap(com.facebook.presto.sql.planner.NodePartitionMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PartitioningHandle(com.facebook.presto.sql.planner.PartitioningHandle) SplitSource(com.facebook.presto.split.SplitSource)

Example 2 with StageExecutionPlan

use of com.facebook.presto.sql.planner.StageExecutionPlan in project presto by prestodb.

the class TestSourcePartitionedScheduler method createPlan.

private static StageExecutionPlan createPlan(ConnectorSplitSource splitSource) {
    Symbol symbol = new Symbol("column");
    // table scan with splitCount splits
    PlanNodeId tableScanNodeId = new PlanNodeId("plan_id");
    TableScanNode tableScan = new TableScanNode(tableScanNodeId, new TableHandle(CONNECTOR_ID, new TestingTableHandle()), ImmutableList.of(symbol), ImmutableMap.of(symbol, new TestingColumnHandle("column")), Optional.empty(), TupleDomain.all(), null);
    RemoteSourceNode remote = new RemoteSourceNode(new PlanNodeId("remote_id"), new PlanFragmentId("plan_fragment_id"), ImmutableList.of());
    PlanFragment testFragment = new PlanFragment(new PlanFragmentId("plan_id"), new JoinNode(new PlanNodeId("join_id"), INNER, tableScan, remote, ImmutableList.of(), ImmutableList.<Symbol>builder().addAll(tableScan.getOutputSymbols()).addAll(remote.getOutputSymbols()).build(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(JoinNode.DistributionType.PARTITIONED)), ImmutableMap.of(symbol, VARCHAR), SOURCE_DISTRIBUTION, ImmutableList.of(tableScanNodeId), new PartitioningScheme(Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()), ImmutableList.of(symbol)));
    return new StageExecutionPlan(testFragment, ImmutableMap.of(tableScanNodeId, new ConnectorAwareSplitSource(CONNECTOR_ID, TestingTransactionHandle.create(), splitSource)), ImmutableList.of());
}
Also used : Symbol(com.facebook.presto.sql.planner.Symbol) TestingTableHandle(com.facebook.presto.sql.planner.TestingTableHandle) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) PartitioningScheme(com.facebook.presto.sql.planner.PartitioningScheme) StageExecutionPlan(com.facebook.presto.sql.planner.StageExecutionPlan) PlanFragment(com.facebook.presto.sql.planner.PlanFragment) ConnectorAwareSplitSource(com.facebook.presto.split.ConnectorAwareSplitSource) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) TestingColumnHandle(com.facebook.presto.sql.planner.TestingColumnHandle) RemoteSourceNode(com.facebook.presto.sql.planner.plan.RemoteSourceNode) TableScanNode(com.facebook.presto.sql.planner.plan.TableScanNode) TestingTableHandle(com.facebook.presto.sql.planner.TestingTableHandle) TableHandle(com.facebook.presto.metadata.TableHandle) PlanFragmentId(com.facebook.presto.sql.planner.plan.PlanFragmentId)

Aggregations

StageExecutionPlan (com.facebook.presto.sql.planner.StageExecutionPlan)2 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)2 ConnectorId (com.facebook.presto.connector.ConnectorId)1 SqlStageExecution (com.facebook.presto.execution.SqlStageExecution)1 StageId (com.facebook.presto.execution.StageId)1 TableHandle (com.facebook.presto.metadata.TableHandle)1 Node (com.facebook.presto.spi.Node)1 ConnectorAwareSplitSource (com.facebook.presto.split.ConnectorAwareSplitSource)1 SplitSource (com.facebook.presto.split.SplitSource)1 NodePartitionMap (com.facebook.presto.sql.planner.NodePartitionMap)1 PartitioningHandle (com.facebook.presto.sql.planner.PartitioningHandle)1 PartitioningScheme (com.facebook.presto.sql.planner.PartitioningScheme)1 PlanFragment (com.facebook.presto.sql.planner.PlanFragment)1 Symbol (com.facebook.presto.sql.planner.Symbol)1 TestingColumnHandle (com.facebook.presto.sql.planner.TestingColumnHandle)1 TestingTableHandle (com.facebook.presto.sql.planner.TestingTableHandle)1 JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)1 PlanFragmentId (com.facebook.presto.sql.planner.plan.PlanFragmentId)1 RemoteSourceNode (com.facebook.presto.sql.planner.plan.RemoteSourceNode)1 TableScanNode (com.facebook.presto.sql.planner.plan.TableScanNode)1