Search in sources :

Example 21 with DriverContext

use of com.facebook.presto.operator.DriverContext in project presto by prestodb.

the class TestOrcBatchPageSourceMemoryTracking method testScanFilterAndProjectOperator.

@Test
public void testScanFilterAndProjectOperator() {
    // Numbers used in assertions in this test may change when implementation is modified,
    // feel free to change them if they break in the future
    DriverContext driverContext = testPreparer.newDriverContext();
    SourceOperator operator = testPreparer.newScanFilterAndProjectOperator(driverContext);
    assertEquals(driverContext.getSystemMemoryUsage(), 0);
    int totalRows = 0;
    while (totalRows < NUM_ROWS) {
        assertFalse(operator.isFinished());
        Page page = operator.getOutput();
        assertNotNull(page);
        assertBetweenInclusive(driverContext.getSystemMemoryUsage(), 90_000L, 619999L);
        totalRows += page.getPositionCount();
    }
    // done... in the current implementation finish is not set until output returns a null page
    assertNull(operator.getOutput());
    assertTrue(operator.isFinished());
    assertBetweenInclusive(driverContext.getSystemMemoryUsage(), 0L, 500L);
}
Also used : DriverContext(com.facebook.presto.operator.DriverContext) SourceOperator(com.facebook.presto.operator.SourceOperator) Page(com.facebook.presto.common.Page) Test(org.testng.annotations.Test)

Example 22 with DriverContext

use of com.facebook.presto.operator.DriverContext in project presto by prestodb.

the class TestOrcBatchPageSourceMemoryTracking method testTableScanOperator.

@Test
public void testTableScanOperator() {
    // Numbers used in assertions in this test may change when implementation is modified,
    // feel free to change them if they break in the future
    DriverContext driverContext = testPreparer.newDriverContext();
    SourceOperator operator = testPreparer.newTableScanOperator(driverContext);
    assertEquals(driverContext.getSystemMemoryUsage(), 0);
    int totalRows = 0;
    while (totalRows < 20000) {
        assertFalse(operator.isFinished());
        Page page = operator.getOutput();
        assertNotNull(page);
        page.getBlock(1);
        assertBetweenInclusive(driverContext.getSystemMemoryUsage(), 390000L, 619999L);
        totalRows += page.getPositionCount();
    }
    while (totalRows < 40000) {
        assertFalse(operator.isFinished());
        Page page = operator.getOutput();
        assertNotNull(page);
        page.getBlock(1);
        assertBetweenInclusive(driverContext.getSystemMemoryUsage(), 390000L, 619999L);
        totalRows += page.getPositionCount();
    }
    while (totalRows < NUM_ROWS) {
        assertFalse(operator.isFinished());
        Page page = operator.getOutput();
        assertNotNull(page);
        page.getBlock(1);
        assertBetweenInclusive(driverContext.getSystemMemoryUsage(), 430000L, 459999L);
        totalRows += page.getPositionCount();
    }
    assertFalse(operator.isFinished());
    assertNull(operator.getOutput());
    assertTrue(operator.isFinished());
    assertEquals(driverContext.getSystemMemoryUsage(), 0);
}
Also used : DriverContext(com.facebook.presto.operator.DriverContext) SourceOperator(com.facebook.presto.operator.SourceOperator) Page(com.facebook.presto.common.Page) Test(org.testng.annotations.Test)

Example 23 with DriverContext

use of com.facebook.presto.operator.DriverContext in project presto by prestodb.

the class TestQueryContext method testMoveTaggedAllocations.

@Test
public void testMoveTaggedAllocations() {
    MemoryPool generalPool = new MemoryPool(GENERAL_POOL, new DataSize(10_000, BYTE));
    MemoryPool reservedPool = new MemoryPool(RESERVED_POOL, new DataSize(10_000, BYTE));
    QueryId queryId = new QueryId("query");
    QueryContext queryContext = createQueryContext(queryId, generalPool);
    TaskStateMachine taskStateMachine = new TaskStateMachine(TaskId.valueOf("queryid.0.0.0"), TEST_EXECUTOR);
    TaskContext taskContext = queryContext.addTaskContext(taskStateMachine, TEST_SESSION, Optional.of(PLAN_FRAGMENT.getRoot()), false, false, false, false, false);
    DriverContext driverContext = taskContext.addPipelineContext(0, false, false, false).addDriverContext();
    OperatorContext operatorContext = driverContext.addOperatorContext(0, new PlanNodeId("test"), "test");
    // allocate some memory in the general pool
    LocalMemoryContext memoryContext = operatorContext.aggregateUserMemoryContext().newLocalMemoryContext("test_context");
    memoryContext.setBytes(1_000);
    Map<String, Long> allocations = generalPool.getTaggedMemoryAllocations(queryId);
    assertEquals(allocations, ImmutableMap.of("test_context", 1_000L));
    queryContext.setMemoryPool(reservedPool);
    assertNull(generalPool.getTaggedMemoryAllocations(queryId));
    allocations = reservedPool.getTaggedMemoryAllocations(queryId);
    assertEquals(allocations, ImmutableMap.of("test_context", 1_000L));
    assertEquals(generalPool.getFreeBytes(), 10_000);
    assertEquals(reservedPool.getFreeBytes(), 9_000);
    memoryContext.close();
    assertEquals(generalPool.getFreeBytes(), 10_000);
    assertEquals(reservedPool.getFreeBytes(), 10_000);
}
Also used : DriverContext(com.facebook.presto.operator.DriverContext) LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext) TaskContext(com.facebook.presto.operator.TaskContext) QueryId(com.facebook.presto.spi.QueryId) TaskStateMachine(com.facebook.presto.execution.TaskStateMachine) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) DataSize(io.airlift.units.DataSize) OperatorContext(com.facebook.presto.operator.OperatorContext) Test(org.testng.annotations.Test)

Example 24 with DriverContext

use of com.facebook.presto.operator.DriverContext in project presto by prestodb.

the class PrestoSparkTaskExecution method enqueueDriverSplitRunner.

private synchronized void enqueueDriverSplitRunner(boolean forceRunSplit, List<DriverSplitRunner> runners) {
    // schedule driver to be executed
    List<ListenableFuture<?>> finishedFutures = taskExecutor.enqueueSplits(taskHandle, forceRunSplit, runners);
    checkState(finishedFutures.size() == runners.size(), "Expected %s futures but got %s", runners.size(), finishedFutures.size());
    // when driver completes, update state and fire events
    for (int i = 0; i < finishedFutures.size(); i++) {
        ListenableFuture<?> finishedFuture = finishedFutures.get(i);
        final DriverSplitRunner splitRunner = runners.get(i);
        // record new driver
        remainingDrivers.incrementAndGet();
        Futures.addCallback(finishedFuture, new FutureCallback<Object>() {

            @Override
            public void onSuccess(Object result) {
                try (SetThreadName ignored = new SetThreadName("Task-%s", taskId)) {
                    // record driver is finished
                    remainingDrivers.decrementAndGet();
                    checkTaskCompletion();
                    splitMonitor.splitCompletedEvent(taskId, getDriverStats());
                }
            }

            @Override
            public void onFailure(Throwable cause) {
                try (SetThreadName ignored = new SetThreadName("Task-%s", taskId)) {
                    taskStateMachine.failed(cause);
                    // record driver is finished
                    remainingDrivers.decrementAndGet();
                    // fire failed event with cause
                    splitMonitor.splitFailedEvent(taskId, getDriverStats(), cause);
                }
            }

            private DriverStats getDriverStats() {
                DriverContext driverContext = splitRunner.getDriverContext();
                DriverStats driverStats;
                if (driverContext != null) {
                    driverStats = driverContext.getDriverStats();
                } else {
                    // split runner did not start successfully
                    driverStats = new DriverStats();
                }
                return driverStats;
            }
        }, notificationExecutor);
    }
}
Also used : DriverContext(com.facebook.presto.operator.DriverContext) DriverStats(com.facebook.presto.operator.DriverStats) SetThreadName(com.facebook.airlift.concurrent.SetThreadName) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Aggregations

DriverContext (com.facebook.presto.operator.DriverContext)24 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)13 Test (org.testng.annotations.Test)12 TaskContext (com.facebook.presto.operator.TaskContext)10 OperatorFactory (com.facebook.presto.operator.OperatorFactory)8 Driver (com.facebook.presto.operator.Driver)6 OperatorContext (com.facebook.presto.operator.OperatorContext)6 PagesSpatialIndexFactory (com.facebook.presto.operator.PagesSpatialIndexFactory)5 SpatialIndexBuilderOperatorFactory (com.facebook.presto.operator.SpatialIndexBuilderOperator.SpatialIndexBuilderOperatorFactory)5 SpatialJoinOperatorFactory (com.facebook.presto.operator.SpatialJoinOperator.SpatialJoinOperatorFactory)5 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 RowPagesBuilder (com.facebook.presto.RowPagesBuilder)4 Page (com.facebook.presto.common.Page)4 LocalMemoryContext (com.facebook.presto.memory.context.LocalMemoryContext)4 Split (com.facebook.presto.metadata.Split)4 DriverFactory (com.facebook.presto.operator.DriverFactory)4 PipelineContext (com.facebook.presto.operator.PipelineContext)4 QueryId (com.facebook.presto.spi.QueryId)4 MaterializedResult (com.facebook.presto.testing.MaterializedResult)4 TestingTaskContext (com.facebook.presto.testing.TestingTaskContext)4