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()));
}
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);
}
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);
}
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();
}
}
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);
}
Aggregations