Search in sources :

Example 1 with TableScanOperator

use of com.facebook.presto.operator.TableScanOperator 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

Type (com.facebook.presto.common.type.Type)1 ScheduledSplit (com.facebook.presto.execution.ScheduledSplit)1 TaskSource (com.facebook.presto.execution.TaskSource)1 Split (com.facebook.presto.metadata.Split)1 Driver (com.facebook.presto.operator.Driver)1 TableScanOperator (com.facebook.presto.operator.TableScanOperator)1 ConnectorId (com.facebook.presto.spi.ConnectorId)1 ConnectorSplit (com.facebook.presto.spi.ConnectorSplit)1 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)1 FixedPageSource (com.facebook.presto.spi.FixedPageSource)1 TableHandle (com.facebook.presto.spi.TableHandle)1 ConnectorTransactionHandle (com.facebook.presto.spi.connector.ConnectorTransactionHandle)1 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)1 PageConsumerOperator (com.facebook.presto.testing.PageConsumerOperator)1 Duration (io.airlift.units.Duration)1 Test (org.testng.annotations.Test)1