Search in sources :

Example 6 with PageConsumerOperator

use of com.facebook.presto.testing.PageConsumerOperator in project presto by prestodb.

the class TestSystemMemoryBlocking method testTableScanSystemMemoryBlocking.

@Test
public void testTableScanSystemMemoryBlocking() {
    PlanNodeId sourceId = new PlanNodeId("source");
    final List<Type> types = ImmutableList.of(VARCHAR);
    TableScanOperator source = new TableScanOperator(driverContext.addOperatorContext(1, new PlanNodeId("test"), "values"), sourceId, (session, split, table, columns) -> new FixedPageSource(rowPagesBuilder(types).addSequencePage(10, 1).addSequencePage(10, 1).addSequencePage(10, 1).addSequencePage(10, 1).addSequencePage(10, 1).build()), new TableHandle(new ConnectorId("test"), new ConnectorTableHandle() {
    }, new ConnectorTransactionHandle() {
    }, Optional.empty()), ImmutableList.of());
    PageConsumerOperator sink = createSinkOperator(types);
    Driver driver = Driver.createDriver(driverContext, source, sink);
    assertSame(driver.getDriverContext(), driverContext);
    assertFalse(driver.isFinished());
    Split testSplit = new Split(new ConnectorId("test"), TestingTransactionHandle.create(), new TestSplit());
    driver.updateSource(new TaskSource(sourceId, ImmutableSet.of(new ScheduledSplit(0, sourceId, testSplit)), true));
    ListenableFuture<?> blocked = driver.processFor(new Duration(1, NANOSECONDS));
    // the driver shouldn't block in the first call as it will be able to move a page between source and the sink operator
    // but the operator should be blocked
    assertTrue(blocked.isDone());
    assertFalse(source.getOperatorContext().isWaitingForMemory().isDone());
    // and they should stay blocked until more memory becomes available
    for (int i = 0; i < 10; i++) {
        blocked = driver.processFor(new Duration(1, NANOSECONDS));
        assertFalse(blocked.isDone());
        assertFalse(source.getOperatorContext().isWaitingForMemory().isDone());
    }
    // free up some memory
    memoryPool.free(QUERY_ID, "test", memoryPool.getReservedBytes());
    // the operator should be unblocked
    assertTrue(source.getOperatorContext().isWaitingForMemory().isDone());
    // the driver shouldn't be blocked
    blocked = driver.processFor(new Duration(1, NANOSECONDS));
    assertTrue(blocked.isDone());
}
Also used : TableScanOperator(com.facebook.presto.operator.TableScanOperator) ScheduledSplit(com.facebook.presto.execution.ScheduledSplit) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) Driver(com.facebook.presto.operator.Driver) Duration(io.airlift.units.Duration) FixedPageSource(com.facebook.presto.spi.FixedPageSource) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PageConsumerOperator(com.facebook.presto.testing.PageConsumerOperator) Type(com.facebook.presto.common.type.Type) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) TableHandle(com.facebook.presto.spi.TableHandle) ScheduledSplit(com.facebook.presto.execution.ScheduledSplit) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) Split(com.facebook.presto.metadata.Split) TaskSource(com.facebook.presto.execution.TaskSource) ConnectorId(com.facebook.presto.spi.ConnectorId) Test(org.testng.annotations.Test)

Aggregations

PageConsumerOperator (com.facebook.presto.testing.PageConsumerOperator)6 Type (com.facebook.presto.common.type.Type)4 FixedPageSource (com.facebook.presto.spi.FixedPageSource)4 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)4 Duration (io.airlift.units.Duration)4 ScheduledSplit (com.facebook.presto.execution.ScheduledSplit)3 TaskSource (com.facebook.presto.execution.TaskSource)3 Test (org.testng.annotations.Test)3 Split (com.facebook.presto.metadata.Split)2 ConnectorSplit (com.facebook.presto.spi.ConnectorSplit)2 Type (com.facebook.presto.spi.type.Type)2 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)2 ScheduledSplit (com.facebook.presto.ScheduledSplit)1 Session (com.facebook.presto.Session)1 TaskSource (com.facebook.presto.TaskSource)1 Driver (com.facebook.presto.operator.Driver)1 TableScanOperator (com.facebook.presto.operator.TableScanOperator)1 ColumnHandle (com.facebook.presto.spi.ColumnHandle)1 ConnectorId (com.facebook.presto.spi.ConnectorId)1 ConnectorPageSource (com.facebook.presto.spi.ConnectorPageSource)1