Search in sources :

Example 1 with OutputBuffers

use of io.prestosql.execution.buffer.OutputBuffers in project hetu-core by openlookeng.

the class SqlStageExecution method scheduleTask.

private synchronized RemoteTask scheduleTask(InternalNode node, TaskId taskId, String instanceId, Multimap<PlanNodeId, Split> sourceSplits, OptionalInt totalPartitions) {
    checkArgument(!allTasks.contains(taskId), "A task with id %s already exists", taskId);
    if (SystemSessionProperties.isSnapshotEnabled(stateMachine.getSession())) {
        // Snapshot: inform snapshot manager so it knows about all tasks,
        // and can determine if a snapshot is complete for all tasks.
        snapshotManager.addNewTask(taskId);
    }
    ImmutableMultimap.Builder<PlanNodeId, Split> initialSplits = ImmutableMultimap.builder();
    initialSplits.putAll(sourceSplits);
    sourceTasks.forEach((planNodeId, task) -> {
        if (task.getTaskStatus().getState() != TaskState.FINISHED) {
            initialSplits.put(planNodeId, newConnectSplit(taskId, task));
        }
    });
    OutputBuffers localOutputBuffers = this.outputBuffers.get();
    checkState(localOutputBuffers != null, "Initial output buffers must be set before a task can be scheduled");
    RemoteTask task = remoteTaskFactory.createRemoteTask(stateMachine.getSession(), taskId, instanceId, node, stateMachine.getFragment(), initialSplits.build(), totalPartitions, localOutputBuffers, nodeTaskMap.createPartitionedSplitCountTracker(node, taskId), summarizeTaskInfo, Optional.ofNullable(parentId), snapshotManager);
    completeSources.forEach(task::noMoreSplits);
    allTasks.add(taskId);
    tasks.computeIfAbsent(node, key -> newConcurrentHashSet()).add(task);
    nodeTaskMap.addTask(node, task);
    task.addStateChangeListener(new StageTaskListener());
    task.addFinalTaskInfoListener(this::updateFinalTaskInfo);
    if (!stateMachine.getState().isDone()) {
        task.start();
    } else {
        // stage finished while we were scheduling this task
        task.abort();
    }
    return task;
}
Also used : PlanNodeId(io.prestosql.spi.plan.PlanNodeId) REMOTE_HOST_GONE(io.prestosql.spi.StandardErrorCode.REMOTE_HOST_GONE) SystemSessionProperties(io.prestosql.SystemSessionProperties) SystemSessionProperties.isSnapshotEnabled(io.prestosql.SystemSessionProperties.isSnapshotEnabled) PlanFragmentId(io.prestosql.sql.planner.plan.PlanFragmentId) Duration(io.airlift.units.Duration) HttpPageBufferClient(io.prestosql.operator.HttpPageBufferClient) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) HashMultimap(com.google.common.collect.HashMultimap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) URI(java.net.URI) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) PrestoException(io.prestosql.spi.PrestoException) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) GONE(io.prestosql.failuredetector.FailureDetector.State.GONE) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TableScanNode(io.prestosql.spi.plan.TableScanNode) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) PlanNode(io.prestosql.spi.plan.PlanNode) UUID(java.util.UUID) GuardedBy(javax.annotation.concurrent.GuardedBy) REMOTE_CONNECTOR_ID(io.prestosql.operator.ExchangeOperator.REMOTE_CONNECTOR_ID) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) SplitSchedulerStats(io.prestosql.execution.scheduler.SplitSchedulerStats) Entry(java.util.Map.Entry) HttpUriBuilder.uriBuilderFrom(io.airlift.http.client.HttpUriBuilder.uriBuilderFrom) GENERIC_INTERNAL_ERROR(io.prestosql.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR) Optional(java.util.Optional) StateChangeListener(io.prestosql.execution.StateMachine.StateChangeListener) Logger(io.airlift.log.Logger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RemoteSourceNode(io.prestosql.sql.planner.plan.RemoteSourceNode) Split(io.prestosql.metadata.Split) Multimap(com.google.common.collect.Multimap) OutputBuffers(io.prestosql.execution.buffer.OutputBuffers) OptionalInt(java.util.OptionalInt) AtomicReference(java.util.concurrent.atomic.AtomicReference) SemiJoinNode(io.prestosql.sql.planner.plan.SemiJoinNode) ArrayList(java.util.ArrayList) SystemSessionProperties.isEnableDynamicFiltering(io.prestosql.SystemSessionProperties.isEnableDynamicFiltering) HashSet(java.util.HashSet) RemoteSplit(io.prestosql.split.RemoteSplit) ImmutableList(com.google.common.collect.ImmutableList) SystemSessionProperties.isReuseTableScanEnabled(io.prestosql.SystemSessionProperties.isReuseTableScanEnabled) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) QueryId(io.prestosql.spi.QueryId) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) ExecutorService(java.util.concurrent.ExecutorService) JoinNode(io.prestosql.spi.plan.JoinNode) PlanFragment(io.prestosql.sql.planner.PlanFragment) SimpleHttpResponseHandler(io.prestosql.server.remotetask.SimpleHttpResponseHandler) Executor(java.util.concurrent.Executor) InternalNode(io.prestosql.metadata.InternalNode) Sets.newConcurrentHashSet(com.google.common.collect.Sets.newConcurrentHashSet) QuerySnapshotManager(io.prestosql.snapshot.QuerySnapshotManager) DynamicFilterService(io.prestosql.dynamicfilter.DynamicFilterService) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) HttpStatus(io.airlift.http.client.HttpStatus) FailureDetector(io.prestosql.failuredetector.FailureDetector) Collections(java.util.Collections) OutputBuffers(io.prestosql.execution.buffer.OutputBuffers) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Split(io.prestosql.metadata.Split) RemoteSplit(io.prestosql.split.RemoteSplit)

Example 2 with OutputBuffers

use of io.prestosql.execution.buffer.OutputBuffers in project hetu-core by openlookeng.

the class SqlQueryExecution method planDistribution.

private void planDistribution(PlanRoot plan) {
    // time distribution planning
    stateMachine.beginDistributedPlanning();
    // plan the execution on the active nodes
    DistributedExecutionPlanner distributedPlanner = new DistributedExecutionPlanner(splitManager, metadata);
    StageExecutionPlan outputStageExecutionPlan;
    Session session = stateMachine.getSession();
    if (SystemSessionProperties.isSnapshotEnabled(session)) {
        // Snapshot: need to plan different when snapshot is enabled.
        // See the "plan" method for difference between the different modes.
        MarkerAnnouncer announcer = splitManager.getMarkerAnnouncer(session);
        announcer.setSnapshotManager(snapshotManager);
        outputStageExecutionPlan = distributedPlanner.plan(plan.getRoot(), session, SNAPSHOT, null, announcer.currentSnapshotId());
    } else {
        outputStageExecutionPlan = distributedPlanner.plan(plan.getRoot(), session, NORMAL, null, 0);
    }
    stateMachine.endDistributedPlanning();
    // 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 output field
    stateMachine.setColumns(outputStageExecutionPlan.getFieldNames(), outputStageExecutionPlan.getFragment().getTypes());
    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 = createSqlQueryScheduler(stateMachine, locationFactory, outputStageExecutionPlan, nodePartitioningManager, nodeScheduler, remoteTaskFactory, stateMachine.getSession(), plan.isSummarizeTaskInfos(), scheduleSplitBatchSize, queryExecutor, schedulerExecutor, failureDetector, rootOutputBuffers, nodeTaskMap, executionPolicy, schedulerStats, dynamicFilterService, heuristicIndexerManager, snapshotManager, null);
    queryScheduler.set(scheduler);
    // directly since the callback may have already fired
    if (stateMachine.isDone()) {
        scheduler.abort();
        queryScheduler.set(null);
    }
}
Also used : MarkerAnnouncer(io.prestosql.snapshot.MarkerAnnouncer) OutputBuffers.createInitialEmptyOutputBuffers(io.prestosql.execution.buffer.OutputBuffers.createInitialEmptyOutputBuffers) OutputBuffers(io.prestosql.execution.buffer.OutputBuffers) StageExecutionPlan(io.prestosql.sql.planner.StageExecutionPlan) SqlQueryScheduler.createSqlQueryScheduler(io.prestosql.execution.scheduler.SqlQueryScheduler.createSqlQueryScheduler) SqlQueryScheduler(io.prestosql.execution.scheduler.SqlQueryScheduler) PartitioningHandle(io.prestosql.sql.planner.PartitioningHandle) DistributedExecutionPlanner(io.prestosql.sql.planner.DistributedExecutionPlanner) Session(io.prestosql.Session)

Example 3 with OutputBuffers

use of io.prestosql.execution.buffer.OutputBuffers in project hetu-core by openlookeng.

the class SqlQueryExecution method resumeQuery.

private void resumeQuery(PlanRoot plan) {
    SqlQueryScheduler oldScheduler = queryScheduler.get();
    try {
        // Wait for previous scheduler to finish.
        // This is important, otherwise the old schedule may close split sources after the new scheduler has started.
        oldScheduler.doneScheduling().get();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    log.debug("Rescheduling query %s from a resumable task failure.", getQueryId());
    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;
    try {
        scheduler = createResumeScheduler(plan, rootOutputBuffers);
    } catch (PrestoException e) {
        if (e.getErrorCode() == NO_NODES_AVAILABLE.toErrorCode()) {
            // Not enough worker to resume all tasks. Retrying from any saved snapshot likely wont' work either.
            // Clear ongoing and existing snapshots and restart.
            snapshotManager.invalidateAllSnapshots();
            scheduler = createResumeScheduler(plan, rootOutputBuffers);
        } else {
            throw e;
        }
    }
    queryScheduler.set(scheduler);
    log.debug("Restarting query %s from a resumable task failure.", getQueryId());
    scheduler.start();
    stateMachine.transitionToStarting();
}
Also used : OutputBuffers.createInitialEmptyOutputBuffers(io.prestosql.execution.buffer.OutputBuffers.createInitialEmptyOutputBuffers) OutputBuffers(io.prestosql.execution.buffer.OutputBuffers) SqlQueryScheduler.createSqlQueryScheduler(io.prestosql.execution.scheduler.SqlQueryScheduler.createSqlQueryScheduler) SqlQueryScheduler(io.prestosql.execution.scheduler.SqlQueryScheduler) PrestoException(io.prestosql.spi.PrestoException) PartitioningHandle(io.prestosql.sql.planner.PartitioningHandle) PrestoException(io.prestosql.spi.PrestoException)

Example 4 with OutputBuffers

use of io.prestosql.execution.buffer.OutputBuffers in project hetu-core by openlookeng.

the class BroadcastOutputBufferManager method addOutputBuffers.

@Override
public void addOutputBuffers(List<OutputBufferId> newBuffers, boolean noMoreBuffers) {
    OutputBuffers newOutputBuffers;
    synchronized (this) {
        if (outputBuffers.isNoMoreBufferIds()) {
            // the new buffers
            return;
        }
        OutputBuffers originalOutputBuffers = outputBuffers;
        // Note: it does not matter which partition id the task is using, in broadcast all tasks read from the same partition
        for (OutputBufferId newBuffer : newBuffers) {
            outputBuffers = outputBuffers.withBuffer(newBuffer, BROADCAST_PARTITION_ID);
        }
        if (noMoreBuffers) {
            outputBuffers = outputBuffers.withNoMoreBufferIds();
        }
        // don't update if nothing changed
        if (outputBuffers == originalOutputBuffers) {
            return;
        }
        newOutputBuffers = this.outputBuffers;
    }
    outputBufferTarget.accept(newOutputBuffers);
}
Also used : OutputBuffers(io.prestosql.execution.buffer.OutputBuffers) OutputBuffers.createInitialEmptyOutputBuffers(io.prestosql.execution.buffer.OutputBuffers.createInitialEmptyOutputBuffers) OutputBufferId(io.prestosql.execution.buffer.OutputBuffers.OutputBufferId)

Example 5 with OutputBuffers

use of io.prestosql.execution.buffer.OutputBuffers in project hetu-core by openlookeng.

the class ScaledOutputBufferManager method addOutputBuffers.

@SuppressWarnings("ObjectEquality")
@Override
public void addOutputBuffers(List<OutputBufferId> newBuffers, boolean noMoreBuffers) {
    OutputBuffers newOutputBuffers;
    synchronized (this) {
        if (outputBuffers.isNoMoreBufferIds()) {
            // so ignore the new buffers
            return;
        }
        OutputBuffers originalOutputBuffers = outputBuffers;
        for (OutputBufferId newBuffer : newBuffers) {
            outputBuffers = outputBuffers.withBuffer(newBuffer, newBuffer.getId());
        }
        if (noMoreBuffers) {
            outputBuffers = outputBuffers.withNoMoreBufferIds();
        }
        // don't update if nothing changed
        if (outputBuffers == originalOutputBuffers) {
            return;
        }
        newOutputBuffers = this.outputBuffers;
    }
    outputBufferTarget.accept(newOutputBuffers);
}
Also used : OutputBuffers(io.prestosql.execution.buffer.OutputBuffers) OutputBuffers.createInitialEmptyOutputBuffers(io.prestosql.execution.buffer.OutputBuffers.createInitialEmptyOutputBuffers) OutputBufferId(io.prestosql.execution.buffer.OutputBuffers.OutputBufferId)

Aggregations

OutputBuffers (io.prestosql.execution.buffer.OutputBuffers)7 OutputBuffers.createInitialEmptyOutputBuffers (io.prestosql.execution.buffer.OutputBuffers.createInitialEmptyOutputBuffers)6 OutputBufferId (io.prestosql.execution.buffer.OutputBuffers.OutputBufferId)3 Session (io.prestosql.Session)2 SqlQueryScheduler (io.prestosql.execution.scheduler.SqlQueryScheduler)2 SqlQueryScheduler.createSqlQueryScheduler (io.prestosql.execution.scheduler.SqlQueryScheduler.createSqlQueryScheduler)2 PrestoException (io.prestosql.spi.PrestoException)2 PartitioningHandle (io.prestosql.sql.planner.PartitioningHandle)2 Test (org.testng.annotations.Test)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 HashMultimap (com.google.common.collect.HashMultimap)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Multimap (com.google.common.collect.Multimap)1 Sets (com.google.common.collect.Sets)1 Sets.newConcurrentHashSet (com.google.common.collect.Sets.newConcurrentHashSet)1