Search in sources :

Example 1 with TableScanOperator

use of io.trino.operator.TableScanOperator in project trino by trinodb.

the class TestMemoryBlocking method testTableScanMemoryBlocking.

@Test
public void testTableScanMemoryBlocking() {
    PlanNodeId sourceId = new PlanNodeId("source");
    List<Type> types = ImmutableList.of(VARCHAR);
    TableScanOperator source = new TableScanOperator(driverContext.addOperatorContext(1, new PlanNodeId("test"), "values"), sourceId, (session, split, table, columns, dynamicFilter) -> new FixedPageSource(rowPagesBuilder(types).addSequencePage(10, 1).addSequencePage(10, 1).addSequencePage(10, 1).addSequencePage(10, 1).addSequencePage(10, 1).build()), TEST_TABLE_HANDLE, ImmutableList.of(), DynamicFilter.EMPTY);
    PageConsumerOperator sink = createSinkOperator(types);
    Driver driver = Driver.createDriver(driverContext, source, sink);
    assertSame(driver.getDriverContext(), driverContext);
    assertFalse(driver.isFinished());
    Split testSplit = new Split(new CatalogName("test"), new TestSplit(), Lifespan.taskWide());
    driver.updateSplitAssignment(new SplitAssignment(sourceId, ImmutableSet.of(new ScheduledSplit(0, sourceId, testSplit)), true));
    ListenableFuture<Void> 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(io.trino.operator.TableScanOperator) ScheduledSplit(io.trino.execution.ScheduledSplit) Driver(io.trino.operator.Driver) SplitAssignment(io.trino.execution.SplitAssignment) Duration(io.airlift.units.Duration) FixedPageSource(io.trino.spi.connector.FixedPageSource) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) PageConsumerOperator(io.trino.testing.PageConsumerOperator) Type(io.trino.spi.type.Type) CatalogName(io.trino.connector.CatalogName) ConnectorSplit(io.trino.spi.connector.ConnectorSplit) ScheduledSplit(io.trino.execution.ScheduledSplit) Split(io.trino.metadata.Split) Test(org.testng.annotations.Test)

Aggregations

Duration (io.airlift.units.Duration)1 CatalogName (io.trino.connector.CatalogName)1 ScheduledSplit (io.trino.execution.ScheduledSplit)1 SplitAssignment (io.trino.execution.SplitAssignment)1 Split (io.trino.metadata.Split)1 Driver (io.trino.operator.Driver)1 TableScanOperator (io.trino.operator.TableScanOperator)1 ConnectorSplit (io.trino.spi.connector.ConnectorSplit)1 FixedPageSource (io.trino.spi.connector.FixedPageSource)1 Type (io.trino.spi.type.Type)1 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)1 PageConsumerOperator (io.trino.testing.PageConsumerOperator)1 Test (org.testng.annotations.Test)1