Search in sources :

Example 1 with OutputBuffers

use of com.facebook.presto.OutputBuffers in project presto by prestodb.

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(com.facebook.presto.OutputBuffers) OutputBuffers.createInitialEmptyOutputBuffers(com.facebook.presto.OutputBuffers.createInitialEmptyOutputBuffers) OutputBufferId(com.facebook.presto.OutputBuffers.OutputBufferId)

Example 2 with OutputBuffers

use of com.facebook.presto.OutputBuffers in project presto by prestodb.

the class SqlStageExecution method scheduleTask.

private synchronized RemoteTask scheduleTask(Node node, TaskId taskId, Multimap<PlanNodeId, Split> sourceSplits) {
    checkArgument(!allTasks.contains(taskId), "A task with id %s already exists", taskId);
    ImmutableMultimap.Builder<PlanNodeId, Split> initialSplits = ImmutableMultimap.builder();
    initialSplits.putAll(sourceSplits);
    for (Entry<PlanNodeId, URI> entry : exchangeLocations.entries()) {
        initialSplits.put(entry.getKey(), createRemoteSplitFor(taskId, entry.getValue()));
    }
    OutputBuffers outputBuffers = this.outputBuffers.get();
    checkState(outputBuffers != null, "Initial output buffers must be set before a task can be scheduled");
    RemoteTask task = remoteTaskFactory.createRemoteTask(stateMachine.getSession(), taskId, node, stateMachine.getFragment(), initialSplits.build(), outputBuffers, nodeTaskMap.createPartitionedSplitCountTracker(node, taskId), summarizeTaskInfo);
    completeSources.forEach(task::noMoreSplits);
    allTasks.add(taskId);
    tasks.computeIfAbsent(node, key -> newConcurrentHashSet()).add(task);
    nodeTaskMap.addTask(node, task);
    task.addStateChangeListener(new StageTaskListener());
    if (!stateMachine.getState().isDone()) {
        task.start();
    } else {
        // stage finished while we were scheduling this task
        task.abort();
    }
    return task;
}
Also used : PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) OutputBuffers(com.facebook.presto.OutputBuffers) RemoteSourceNode(com.facebook.presto.sql.planner.plan.RemoteSourceNode) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PrestoException(com.facebook.presto.spi.PrestoException) Multimap(com.google.common.collect.Multimap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Duration(io.airlift.units.Duration) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) PlanFragment(com.facebook.presto.sql.planner.PlanFragment) HashMultimap(com.google.common.collect.HashMultimap) Node(com.facebook.presto.spi.Node) ImmutableList(com.google.common.collect.ImmutableList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) RemoteSplit(com.facebook.presto.split.RemoteSplit) PlanFragmentId(com.facebook.presto.sql.planner.plan.PlanFragmentId) URI(java.net.URI) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) RemoteTransactionHandle(com.facebook.presto.metadata.RemoteTransactionHandle) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) ExecutorService(java.util.concurrent.ExecutorService) ImmutableSet(com.google.common.collect.ImmutableSet) SplitSchedulerStats(com.facebook.presto.execution.scheduler.SplitSchedulerStats) ImmutableMap(com.google.common.collect.ImmutableMap) Session(com.facebook.presto.Session) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Sets.newConcurrentHashSet(com.google.common.collect.Sets.newConcurrentHashSet) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) Preconditions.checkState(com.google.common.base.Preconditions.checkState) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) StateChangeListener(com.facebook.presto.execution.StateMachine.StateChangeListener) StandardErrorCode(com.facebook.presto.spi.StandardErrorCode) REMOTE_CONNECTOR_ID(com.facebook.presto.operator.ExchangeOperator.REMOTE_CONNECTOR_ID) Entry(java.util.Map.Entry) HttpUriBuilder.uriBuilderFrom(io.airlift.http.client.HttpUriBuilder.uriBuilderFrom) Split(com.facebook.presto.metadata.Split) OutputBuffers(com.facebook.presto.OutputBuffers) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) RemoteSplit(com.facebook.presto.split.RemoteSplit) Split(com.facebook.presto.metadata.Split) URI(java.net.URI)

Example 3 with OutputBuffers

use of com.facebook.presto.OutputBuffers 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 4 with OutputBuffers

use of com.facebook.presto.OutputBuffers in project presto by prestodb.

the class TestArbitraryOutputBuffer method testAddQueueAfterNoMoreQueues.

@Test
public void testAddQueueAfterNoMoreQueues() throws Exception {
    ArbitraryOutputBuffer buffer = createArbitraryBuffer(createInitialEmptyOutputBuffers(ARBITRARY), sizeOfPages(10));
    assertFalse(buffer.isFinished());
    // tell buffer no more queues will be added
    buffer.setOutputBuffers(createInitialEmptyOutputBuffers(ARBITRARY).withNoMoreBufferIds());
    assertFalse(buffer.isFinished());
    // set no more queues a second time to assure that we don't get an exception or such
    buffer.setOutputBuffers(createInitialEmptyOutputBuffers(ARBITRARY).withNoMoreBufferIds());
    assertFalse(buffer.isFinished());
    // set no more queues a third time to assure that we don't get an exception or such
    buffer.setOutputBuffers(createInitialEmptyOutputBuffers(ARBITRARY).withNoMoreBufferIds());
    assertFalse(buffer.isFinished());
    try {
        OutputBuffers outputBuffers = createInitialEmptyOutputBuffers(ARBITRARY).withBuffer(FIRST, BROADCAST_PARTITION_ID).withNoMoreBufferIds();
        buffer.setOutputBuffers(outputBuffers);
        fail("Expected IllegalStateException from addQueue after noMoreQueues has been called");
    } catch (IllegalArgumentException ignored) {
    }
}
Also used : OutputBuffers(com.facebook.presto.OutputBuffers) OutputBuffers.createInitialEmptyOutputBuffers(com.facebook.presto.OutputBuffers.createInitialEmptyOutputBuffers) Test(org.testng.annotations.Test)

Example 5 with OutputBuffers

use of com.facebook.presto.OutputBuffers in project presto by prestodb.

the class TestArbitraryOutputBuffer method testAbort.

@Test
public void testAbort() throws Exception {
    ArbitraryOutputBuffer buffer = createArbitraryBuffer(createInitialEmptyOutputBuffers(ARBITRARY), sizeOfPages(10));
    // fill the buffer
    for (int i = 0; i < 10; i++) {
        addPage(buffer, createPage(i));
    }
    buffer.setNoMorePages();
    // add one output buffer
    OutputBuffers outputBuffers = createInitialEmptyOutputBuffers(ARBITRARY).withBuffer(FIRST, 0);
    buffer.setOutputBuffers(outputBuffers);
    // read a page from the first buffer
    assertBufferResultEquals(TYPES, getBufferResult(buffer, FIRST, 0, sizeOfPages(1), NO_WAIT), bufferResult(0, createPage(0)));
    // abort buffer, and verify page cannot be acknowledged
    buffer.abort(FIRST);
    assertQueueClosed(buffer, 9, FIRST, 0);
    assertBufferResultEquals(TYPES, getBufferResult(buffer, FIRST, 1, sizeOfPages(1), NO_WAIT), emptyResults(TASK_INSTANCE_ID, 0, true));
    outputBuffers = outputBuffers.withBuffer(SECOND, 0).withNoMoreBufferIds();
    buffer.setOutputBuffers(outputBuffers);
    // first page is lost because the first buffer was aborted
    assertBufferResultEquals(TYPES, getBufferResult(buffer, SECOND, 0, sizeOfPages(1), NO_WAIT), bufferResult(0, createPage(1)));
    buffer.abort(SECOND);
    assertQueueClosed(buffer, 0, SECOND, 0);
    assertFinished(buffer);
    assertBufferResultEquals(TYPES, getBufferResult(buffer, SECOND, 1, sizeOfPages(1), NO_WAIT), emptyResults(TASK_INSTANCE_ID, 0, true));
}
Also used : OutputBuffers(com.facebook.presto.OutputBuffers) OutputBuffers.createInitialEmptyOutputBuffers(com.facebook.presto.OutputBuffers.createInitialEmptyOutputBuffers) Test(org.testng.annotations.Test)

Aggregations

OutputBuffers (com.facebook.presto.OutputBuffers)10 OutputBuffers.createInitialEmptyOutputBuffers (com.facebook.presto.OutputBuffers.createInitialEmptyOutputBuffers)9 Test (org.testng.annotations.Test)7 OutputBufferId (com.facebook.presto.OutputBuffers.OutputBufferId)2 Session (com.facebook.presto.Session)1 TaskSource (com.facebook.presto.TaskSource)1 StateChangeListener (com.facebook.presto.execution.StateMachine.StateChangeListener)1 BufferResult (com.facebook.presto.execution.buffer.BufferResult)1 SplitSchedulerStats (com.facebook.presto.execution.scheduler.SplitSchedulerStats)1 SqlQueryScheduler (com.facebook.presto.execution.scheduler.SqlQueryScheduler)1 RemoteTransactionHandle (com.facebook.presto.metadata.RemoteTransactionHandle)1 Split (com.facebook.presto.metadata.Split)1 REMOTE_CONNECTOR_ID (com.facebook.presto.operator.ExchangeOperator.REMOTE_CONNECTOR_ID)1 Node (com.facebook.presto.spi.Node)1 PrestoException (com.facebook.presto.spi.PrestoException)1 StandardErrorCode (com.facebook.presto.spi.StandardErrorCode)1 RemoteSplit (com.facebook.presto.split.RemoteSplit)1 DistributedExecutionPlanner (com.facebook.presto.sql.planner.DistributedExecutionPlanner)1 PartitioningHandle (com.facebook.presto.sql.planner.PartitioningHandle)1 PlanFragment (com.facebook.presto.sql.planner.PlanFragment)1