Search in sources :

Example 16 with LocalMemoryContext

use of io.trino.memory.context.LocalMemoryContext in project trino by trinodb.

the class TestMemoryTracking method testTrySetZeroBytesFullPool.

@Test
public void testTrySetZeroBytesFullPool() {
    LocalMemoryContext localMemoryContext = operatorContext.localUserMemoryContext();
    // fill up the pool
    memoryPool.reserve(new QueryId("test_query"), "test", memoryPool.getFreeBytes());
    // try to reserve 0 bytes in the full pool
    assertTrue(localMemoryContext.trySetBytes(localMemoryContext.getBytes()));
}
Also used : LocalMemoryContext(io.trino.memory.context.LocalMemoryContext) QueryId(io.trino.spi.QueryId) Test(org.testng.annotations.Test)

Example 17 with LocalMemoryContext

use of io.trino.memory.context.LocalMemoryContext in project trino by trinodb.

the class TestMemoryTracking method testLocalAllocations.

@Test
public void testLocalAllocations() {
    long pipelineLocalAllocation = 1_000_000;
    long taskLocalAllocation = 10_000_000;
    LocalMemoryContext pipelineLocalMemoryContext = pipelineContext.localMemoryContext();
    pipelineLocalMemoryContext.setBytes(pipelineLocalAllocation);
    assertLocalMemoryAllocations(pipelineContext.getPipelineMemoryContext(), pipelineLocalAllocation, 1_000_000);
    LocalMemoryContext taskLocalMemoryContext = taskContext.localMemoryContext();
    taskLocalMemoryContext.setBytes(taskLocalAllocation);
    assertLocalMemoryAllocations(taskContext.getTaskMemoryContext(), pipelineLocalAllocation + taskLocalAllocation, 11_000_000);
    assertEquals(pipelineContext.getPipelineStats().getUserMemoryReservation().toBytes(), pipelineLocalAllocation, "task level allocations should not be visible at the pipeline level");
    pipelineLocalMemoryContext.setBytes(pipelineLocalMemoryContext.getBytes() - pipelineLocalAllocation);
    assertLocalMemoryAllocations(pipelineContext.getPipelineMemoryContext(), taskLocalAllocation, 0);
    taskLocalMemoryContext.setBytes(taskLocalMemoryContext.getBytes() - taskLocalAllocation);
    assertLocalMemoryAllocations(taskContext.getTaskMemoryContext(), 0, 0);
}
Also used : LocalMemoryContext(io.trino.memory.context.LocalMemoryContext) Test(org.testng.annotations.Test)

Example 18 with LocalMemoryContext

use of io.trino.memory.context.LocalMemoryContext in project trino by trinodb.

the class TestMemoryTracking method testOperatorAllocations.

@Test
public void testOperatorAllocations() {
    MemoryTrackingContext operatorMemoryContext = operatorContext.getOperatorMemoryContext();
    LocalMemoryContext userMemory = operatorContext.localUserMemoryContext();
    LocalMemoryContext revocableMemory = operatorContext.localRevocableMemoryContext();
    userMemory.setBytes(100);
    assertOperatorMemoryAllocations(operatorMemoryContext, 100, 0);
    assertOperatorMemoryAllocations(operatorMemoryContext, 100, 0);
    userMemory.setBytes(500);
    assertOperatorMemoryAllocations(operatorMemoryContext, 500, 0);
    userMemory.setBytes(userMemory.getBytes() - 500);
    assertOperatorMemoryAllocations(operatorMemoryContext, 0, 0);
    revocableMemory.setBytes(300);
    assertOperatorMemoryAllocations(operatorMemoryContext, 0, 300);
    assertThatThrownBy(() -> userMemory.setBytes(userMemory.getBytes() - 500)).isInstanceOf(IllegalArgumentException.class).hasMessage("bytes cannot be negative");
    operatorContext.destroy();
    assertOperatorMemoryAllocations(operatorMemoryContext, 0, 0);
}
Also used : LocalMemoryContext(io.trino.memory.context.LocalMemoryContext) MemoryTrackingContext(io.trino.memory.context.MemoryTrackingContext) Test(org.testng.annotations.Test)

Example 19 with LocalMemoryContext

use of io.trino.memory.context.LocalMemoryContext in project trino by trinodb.

the class TestQueryContext method testSetMemoryPool.

@Test
public void testSetMemoryPool() {
    try (LocalQueryRunner localQueryRunner = LocalQueryRunner.create(TEST_SESSION)) {
        QueryContext queryContext = new QueryContext(new QueryId("query"), DataSize.ofBytes(10), new MemoryPool(DataSize.ofBytes(10)), new TestingGcMonitor(), localQueryRunner.getExecutor(), localQueryRunner.getScheduler(), DataSize.ofBytes(0), new SpillSpaceTracker(DataSize.ofBytes(0)));
        // Use memory
        queryContext.getQueryMemoryContext().initializeLocalMemoryContexts("test");
        LocalMemoryContext userMemoryContext = queryContext.getQueryMemoryContext().localUserMemoryContext();
        LocalMemoryContext revocableMemoryContext = queryContext.getQueryMemoryContext().localRevocableMemoryContext();
        assertTrue(userMemoryContext.setBytes(3).isDone());
        assertTrue(revocableMemoryContext.setBytes(5).isDone());
        // Free memory
        userMemoryContext.close();
        revocableMemoryContext.close();
    }
}
Also used : LocalMemoryContext(io.trino.memory.context.LocalMemoryContext) SpillSpaceTracker(io.trino.spiller.SpillSpaceTracker) QueryId(io.trino.spi.QueryId) TestingGcMonitor(io.airlift.stats.TestingGcMonitor) LocalQueryRunner(io.trino.testing.LocalQueryRunner) Test(org.testng.annotations.Test)

Example 20 with LocalMemoryContext

use of io.trino.memory.context.LocalMemoryContext in project trino by trinodb.

the class TestPageProcessor method testSelectNoneFilterLazyLoad.

@Test
public void testSelectNoneFilterLazyLoad() {
    PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectNoneFilter()), ImmutableList.of(new InputPageProjection(1, BIGINT)));
    // if channel 1 is loaded, test will fail
    Page inputPage = new Page(createLongSequenceBlock(0, 100), new LazyBlock(100, () -> {
        throw new AssertionError("Lazy block should not be loaded");
    }));
    LocalMemoryContext memoryContext = newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName());
    Iterator<Optional<Page>> output = pageProcessor.process(SESSION, new DriverYieldSignal(), memoryContext, inputPage);
    assertEquals(memoryContext.getBytes(), 0);
    List<Optional<Page>> outputPages = ImmutableList.copyOf(output);
    assertEquals(outputPages.size(), 0);
}
Also used : LocalMemoryContext(io.trino.memory.context.LocalMemoryContext) LazyBlock(io.trino.spi.block.LazyBlock) Optional(java.util.Optional) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Page(io.trino.spi.Page) Test(org.testng.annotations.Test)

Aggregations

LocalMemoryContext (io.trino.memory.context.LocalMemoryContext)24 Test (org.testng.annotations.Test)17 Page (io.trino.spi.Page)7 DriverYieldSignal (io.trino.operator.DriverYieldSignal)5 Optional (java.util.Optional)5 QueryId (io.trino.spi.QueryId)3 LazyBlock (io.trino.spi.block.LazyBlock)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Suppliers (com.google.common.base.Suppliers)1 Futures.immediateVoidFuture (com.google.common.util.concurrent.Futures.immediateVoidFuture)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 Slice (io.airlift.slice.Slice)1 TestingGcMonitor (io.airlift.stats.TestingGcMonitor)1 ExceededMemoryLimitException (io.trino.ExceededMemoryLimitException)1 SqlTask.createSqlTask (io.trino.execution.SqlTask.createSqlTask)1 QueryContext (io.trino.memory.QueryContext)1 MemoryTrackingContext (io.trino.memory.context.MemoryTrackingContext)1