Search in sources :

Example 6 with TableWriteInfo

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

the class TestMemoryRevokingScheduler method createTestingOperatorContexts.

private TestOperatorContext createTestingOperatorContexts(SqlTask sqlTask, String operatorName) {
    // update task to update underlying taskHolderReference with taskExecution + create a new taskContext
    sqlTask.updateTask(TEST_SESSION, Optional.of(PLAN_FRAGMENT), ImmutableList.of(new TaskSource(TABLE_SCAN_NODE_ID, ImmutableSet.of(SPLIT), false)), createInitialEmptyOutputBuffers(PARTITIONED).withBuffer(OUT, 0).withNoMoreBufferIds(), Optional.of(new TableWriteInfo(Optional.empty(), Optional.empty(), Optional.empty())));
    // use implicitly created task context from updateTask. It should be the only task in this QueryContext's tasks
    TaskContext taskContext = sqlTask.getQueryContext().getTaskContextByTaskId(sqlTask.getTaskId());
    PipelineContext pipelineContext = taskContext.addPipelineContext(0, false, false, false);
    DriverContext driverContext = pipelineContext.addDriverContext();
    TestOperatorContext testOperatorContext = new TestOperatorContext(1, new PlanNodeId("na"), "na", driverContext, singleThreadedExecutor, driverContext.getDriverMemoryContext().newMemoryTrackingContext(), operatorName);
    driverContext.addOperatorContext(testOperatorContext);
    return testOperatorContext;
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) DriverContext(com.facebook.presto.operator.DriverContext) TableWriteInfo(com.facebook.presto.execution.scheduler.TableWriteInfo) TaskContext(com.facebook.presto.operator.TaskContext) PipelineContext(com.facebook.presto.operator.PipelineContext)

Example 7 with TableWriteInfo

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

the class MockRemoteTaskFactory method createTableScanTask.

public MockRemoteTask createTableScanTask(TaskId taskId, InternalNode newNode, List<Split> splits, NodeTaskMap.NodeStatsTracker nodeStatsTracker) {
    VariableReferenceExpression variable = new VariableReferenceExpression(Optional.empty(), "column", VARCHAR);
    PlanNodeId sourceId = new PlanNodeId("sourceId");
    PlanFragment testFragment = new PlanFragment(new PlanFragmentId(0), new TableScanNode(Optional.empty(), sourceId, new TableHandle(new ConnectorId("test"), new TestingTableHandle(), TestingTransactionHandle.create(), Optional.of(TestingHandle.INSTANCE)), ImmutableList.of(variable), ImmutableMap.of(variable, new TestingColumnHandle("column")), TupleDomain.all(), TupleDomain.all()), ImmutableSet.of(variable), SOURCE_DISTRIBUTION, ImmutableList.of(sourceId), new PartitioningScheme(Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()), ImmutableList.of(variable)), StageExecutionDescriptor.ungroupedExecution(), false, StatsAndCosts.empty(), Optional.empty());
    ImmutableMultimap.Builder<PlanNodeId, Split> initialSplits = ImmutableMultimap.builder();
    for (Split sourceSplit : splits) {
        initialSplits.put(sourceId, sourceSplit);
    }
    return createRemoteTask(TEST_SESSION, taskId, newNode, testFragment, initialSplits.build(), createInitialEmptyOutputBuffers(BROADCAST), nodeStatsTracker, true, new TableWriteInfo(Optional.empty(), Optional.empty(), Optional.empty()));
}
Also used : TableWriteInfo(com.facebook.presto.execution.scheduler.TableWriteInfo) TestingTableHandle(com.facebook.presto.testing.TestingMetadata.TestingTableHandle) PartitioningScheme(com.facebook.presto.sql.planner.PartitioningScheme) PlanFragment(com.facebook.presto.sql.planner.PlanFragment) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) TestingColumnHandle(com.facebook.presto.testing.TestingMetadata.TestingColumnHandle) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) TableHandle(com.facebook.presto.spi.TableHandle) TestingTableHandle(com.facebook.presto.testing.TestingMetadata.TestingTableHandle) PlanFragmentId(com.facebook.presto.sql.planner.plan.PlanFragmentId) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Split(com.facebook.presto.metadata.Split) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 8 with TableWriteInfo

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

the class TestSqlTask method testSimpleQuery.

@Test
public void testSimpleQuery() throws Exception {
    SqlTask sqlTask = createInitialTask();
    TaskInfo taskInfo = sqlTask.updateTask(TEST_SESSION, Optional.of(PLAN_FRAGMENT), ImmutableList.of(new TaskSource(TABLE_SCAN_NODE_ID, ImmutableSet.of(SPLIT), true)), createInitialEmptyOutputBuffers(PARTITIONED).withBuffer(OUT, 0).withNoMoreBufferIds(), Optional.of(new TableWriteInfo(Optional.empty(), Optional.empty(), Optional.empty())));
    assertEquals(taskInfo.getTaskStatus().getState(), TaskState.RUNNING);
    taskInfo = sqlTask.getTaskInfo();
    assertEquals(taskInfo.getTaskStatus().getState(), TaskState.RUNNING);
    BufferResult results = sqlTask.getTaskResults(OUT, 0, new DataSize(1, MEGABYTE)).get();
    assertEquals(results.isBufferComplete(), false);
    assertEquals(results.getSerializedPages().size(), 1);
    assertEquals(results.getSerializedPages().get(0).getPositionCount(), 1);
    for (boolean moreResults = true; moreResults; moreResults = !results.isBufferComplete()) {
        results = sqlTask.getTaskResults(OUT, results.getToken() + results.getSerializedPages().size(), new DataSize(1, MEGABYTE)).get();
    }
    assertEquals(results.getSerializedPages().size(), 0);
    // complete the task by calling abort on it
    TaskInfo info = sqlTask.abortTaskResults(OUT);
    assertEquals(info.getOutputBuffers().getState(), BufferState.FINISHED);
    taskInfo = sqlTask.getTaskInfo(taskInfo.getTaskStatus().getState()).get(1, SECONDS);
    assertEquals(taskInfo.getTaskStatus().getState(), TaskState.FINISHED);
    taskInfo = sqlTask.getTaskInfo();
    assertEquals(taskInfo.getTaskStatus().getState(), TaskState.FINISHED);
}
Also used : SqlTask.createSqlTask(com.facebook.presto.execution.SqlTask.createSqlTask) TableWriteInfo(com.facebook.presto.execution.scheduler.TableWriteInfo) BufferResult(com.facebook.presto.execution.buffer.BufferResult) DataSize(io.airlift.units.DataSize) Test(org.testng.annotations.Test)

Example 9 with TableWriteInfo

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

the class TestSqlTask method testAbort.

@Test
public void testAbort() throws Exception {
    SqlTask sqlTask = createInitialTask();
    TaskInfo taskInfo = sqlTask.updateTask(TEST_SESSION, Optional.of(PLAN_FRAGMENT), ImmutableList.of(new TaskSource(TABLE_SCAN_NODE_ID, ImmutableSet.of(SPLIT), true)), createInitialEmptyOutputBuffers(PARTITIONED).withBuffer(OUT, 0).withNoMoreBufferIds(), Optional.of(new TableWriteInfo(Optional.empty(), Optional.empty(), Optional.empty())));
    assertEquals(taskInfo.getTaskStatus().getState(), TaskState.RUNNING);
    taskInfo = sqlTask.getTaskInfo();
    assertEquals(taskInfo.getTaskStatus().getState(), TaskState.RUNNING);
    sqlTask.abortTaskResults(OUT);
    taskInfo = sqlTask.getTaskInfo(taskInfo.getTaskStatus().getState()).get(1, SECONDS);
    assertEquals(taskInfo.getTaskStatus().getState(), TaskState.FINISHED);
    taskInfo = sqlTask.getTaskInfo();
    assertEquals(taskInfo.getTaskStatus().getState(), TaskState.FINISHED);
}
Also used : SqlTask.createSqlTask(com.facebook.presto.execution.SqlTask.createSqlTask) TableWriteInfo(com.facebook.presto.execution.scheduler.TableWriteInfo) Test(org.testng.annotations.Test)

Example 10 with TableWriteInfo

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

the class TestSqlStageExecution method testFinalStageInfoInternal.

private void testFinalStageInfoInternal() throws Exception {
    NodeTaskMap nodeTaskMap = new NodeTaskMap(new FinalizerService());
    StageId stageId = new StageId(new QueryId("query"), 0);
    SqlStageExecution stage = createSqlStageExecution(new StageExecutionId(stageId, 0), createExchangePlanFragment(), new MockRemoteTaskFactory(executor, scheduledExecutor), TEST_SESSION, true, nodeTaskMap, executor, new NoOpFailureDetector(), new SplitSchedulerStats(), new TableWriteInfo(Optional.empty(), Optional.empty(), Optional.empty()));
    stage.setOutputBuffers(createInitialEmptyOutputBuffers(ARBITRARY));
    // add listener that fetches stage info when the final status is available
    SettableFuture<StageExecutionInfo> finalStageInfo = SettableFuture.create();
    stage.addFinalStageInfoListener(finalStageInfo::set);
    // in a background thread add a ton of tasks
    CountDownLatch latch = new CountDownLatch(1000);
    Future<?> addTasksTask = executor.submit(() -> {
        try {
            for (int i = 0; i < 1_000_000; i++) {
                if (Thread.interrupted()) {
                    return;
                }
                InternalNode node = new InternalNode("source" + i, URI.create("http://10.0.0." + (i / 10_000) + ":" + (i % 10_000)), NodeVersion.UNKNOWN, false);
                stage.scheduleTask(node, i);
                latch.countDown();
            }
        } finally {
            while (latch.getCount() > 0) {
                latch.countDown();
            }
        }
    });
    // wait for some tasks to be created, and then abort the query
    latch.await(1, MINUTES);
    assertFalse(stage.getStageExecutionInfo().getTasks().isEmpty());
    stage.abort();
    // once the final stage info is available, verify that it is complete
    StageExecutionInfo stageInfo = finalStageInfo.get(1, MINUTES);
    assertFalse(stageInfo.getTasks().isEmpty());
    assertTrue(stageInfo.isFinal());
    assertSame(stage.getStageExecutionInfo(), stageInfo);
    // cancel the background thread adding tasks
    addTasksTask.cancel(true);
}
Also used : NoOpFailureDetector(com.facebook.presto.failureDetector.NoOpFailureDetector) TableWriteInfo(com.facebook.presto.execution.scheduler.TableWriteInfo) QueryId(com.facebook.presto.spi.QueryId) CountDownLatch(java.util.concurrent.CountDownLatch) SqlStageExecution.createSqlStageExecution(com.facebook.presto.execution.SqlStageExecution.createSqlStageExecution) SplitSchedulerStats(com.facebook.presto.execution.scheduler.SplitSchedulerStats) FinalizerService(com.facebook.presto.util.FinalizerService) InternalNode(com.facebook.presto.metadata.InternalNode)

Aggregations

TableWriteInfo (com.facebook.presto.execution.scheduler.TableWriteInfo)12 SqlTask.createSqlTask (com.facebook.presto.execution.SqlTask.createSqlTask)4 Test (org.testng.annotations.Test)4 PrestoException (com.facebook.presto.spi.PrestoException)3 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)3 Session (com.facebook.presto.Session)2 SplitSchedulerStats (com.facebook.presto.execution.scheduler.SplitSchedulerStats)2 StreamingSubPlan (com.facebook.presto.execution.scheduler.StreamingSubPlan)2 TableWriteInfo.createTableWriteInfo (com.facebook.presto.execution.scheduler.TableWriteInfo.createTableWriteInfo)2 InternalNode (com.facebook.presto.metadata.InternalNode)2 Split (com.facebook.presto.metadata.Split)2 QueryId (com.facebook.presto.spi.QueryId)2 HttpUriBuilder (com.facebook.airlift.http.client.HttpUriBuilder)1 Request (com.facebook.airlift.http.client.Request)1 ResponseHandler (com.facebook.airlift.http.client.ResponseHandler)1 StatusResponseHandler.createStatusResponseHandler (com.facebook.airlift.http.client.StatusResponseHandler.createStatusResponseHandler)1 JsonCodec (com.facebook.airlift.json.JsonCodec)1 SmileCodec (com.facebook.airlift.json.smile.SmileCodec)1 SystemSessionProperties.getMaxFailedTaskPercentage (com.facebook.presto.SystemSessionProperties.getMaxFailedTaskPercentage)1 DDLDefinitionTask (com.facebook.presto.execution.DDLDefinitionTask)1