Search in sources :

Example 11 with LocalMemoryContext

use of com.facebook.presto.memory.context.LocalMemoryContext in project presto by prestodb.

the class TestPageProcessor method testSelectNoneFilter.

@Test
public void testSelectNoneFilter() {
    PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectNoneFilter()), ImmutableList.of(createInputPageProjectionWithOutputs(0, BIGINT, 0)));
    Page inputPage = new Page(createLongSequenceBlock(0, 100));
    LocalMemoryContext memoryContext = newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName());
    Iterator<Optional<Page>> output = pageProcessor.process(SESSION.getSqlFunctionProperties(), new DriverYieldSignal(), memoryContext, inputPage);
    assertEquals(memoryContext.getBytes(), 0);
    List<Optional<Page>> outputPages = ImmutableList.copyOf(output);
    assertEquals(outputPages.size(), 0);
}
Also used : LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext) Optional(java.util.Optional) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) Test(org.testng.annotations.Test)

Example 12 with LocalMemoryContext

use of com.facebook.presto.memory.context.LocalMemoryContext in project presto by prestodb.

the class TestPageProcessor method testFilterNoColumns.

@Test
public void testFilterNoColumns() {
    PageProcessor pageProcessor = new PageProcessor(Optional.of(new TestingPageFilter(positionsRange(0, 50))), ImmutableList.of());
    Page inputPage = new Page(createLongSequenceBlock(0, 100));
    LocalMemoryContext memoryContext = newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName());
    Iterator<Optional<Page>> output = pageProcessor.process(SESSION.getSqlFunctionProperties(), new DriverYieldSignal(), memoryContext, inputPage);
    assertEquals(memoryContext.getBytes(), 0);
    List<Optional<Page>> outputPages = ImmutableList.copyOf(output);
    assertEquals(outputPages.size(), 1);
    Page outputPage = outputPages.get(0).orElse(null);
    assertEquals(outputPage.getChannelCount(), 0);
    assertEquals(outputPage.getPositionCount(), 50);
}
Also used : LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext) Optional(java.util.Optional) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) Test(org.testng.annotations.Test)

Example 13 with LocalMemoryContext

use of com.facebook.presto.memory.context.LocalMemoryContext in project presto by prestodb.

the class TestPageProcessor method testSelectNoneFilterLazyLoad.

@Test
public void testSelectNoneFilterLazyLoad() {
    PageProcessor pageProcessor = new PageProcessor(Optional.of(new SelectNoneFilter()), ImmutableList.of(createInputPageProjectionWithOutputs(1, BIGINT, 0)));
    // if channel 1 is loaded, test will fail
    Page inputPage = new Page(createLongSequenceBlock(0, 100), new LazyBlock(100, lazyBlock -> {
        throw new AssertionError("Lazy block should not be loaded");
    }));
    LocalMemoryContext memoryContext = newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName());
    Iterator<Optional<Page>> output = pageProcessor.process(SESSION.getSqlFunctionProperties(), new DriverYieldSignal(), memoryContext, inputPage);
    assertEquals(memoryContext.getBytes(), 0);
    List<Optional<Page>> outputPages = ImmutableList.copyOf(output);
    assertEquals(outputPages.size(), 0);
}
Also used : TestingTicker(com.facebook.airlift.testing.TestingTicker) Page(com.facebook.presto.common.Page) CompletedWork(com.facebook.presto.operator.CompletedWork) Arrays(java.util.Arrays) MetadataManager(com.facebook.presto.metadata.MetadataManager) Test(org.testng.annotations.Test) Expressions.constant(com.facebook.presto.sql.relational.Expressions.constant) BlockAssertions(com.facebook.presto.block.BlockAssertions) Duration(io.airlift.units.Duration) Expressions.field(com.facebook.presto.sql.relational.Expressions.field) ADD(com.facebook.presto.common.function.OperatorType.ADD) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) SESSION(com.facebook.presto.testing.TestingConnectorSession.SESSION) Slices(io.airlift.slice.Slices) CallExpression(com.facebook.presto.spi.relation.CallExpression) PageFunctionCompiler(com.facebook.presto.sql.gen.PageFunctionCompiler) Assert.assertFalse(org.testng.Assert.assertFalse) SPLIT_RUN_QUANTA(com.facebook.presto.execution.executor.PrioritizedSplitRunner.SPLIT_RUN_QUANTA) Collections.nCopies(java.util.Collections.nCopies) SqlFunctionProperties(com.facebook.presto.common.function.SqlFunctionProperties) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Assert.assertNotNull(org.testng.Assert.assertNotNull) Threads.daemonThreadsNamed(com.facebook.airlift.concurrent.Threads.daemonThreadsNamed) List(java.util.List) ClassLayout(org.openjdk.jol.info.ClassLayout) Optional(java.util.Optional) LazyBlock(com.facebook.presto.common.block.LazyBlock) IntStream(java.util.stream.IntStream) Slice(io.airlift.slice.Slice) Assert.assertNull(org.testng.Assert.assertNull) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) BlockAssertions.createSlicesBlock(com.facebook.presto.block.BlockAssertions.createSlicesBlock) RowType.withDefaultFieldNames(com.facebook.presto.common.type.RowType.withDefaultFieldNames) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) MAX_BATCH_SIZE(com.facebook.presto.operator.project.PageProcessor.MAX_BATCH_SIZE) PageAssertions.assertPageEquals(com.facebook.presto.operator.PageAssertions.assertPageEquals) Assert.assertEquals(org.testng.Assert.assertEquals) VariableWidthBlock(com.facebook.presto.common.block.VariableWidthBlock) OptionalInt(java.util.OptionalInt) Supplier(java.util.function.Supplier) TypeSignatureProvider.fromTypes(com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypes) Expressions.call(com.facebook.presto.sql.relational.Expressions.call) REAL(com.facebook.presto.common.type.RealType.REAL) ImmutableList(com.google.common.collect.ImmutableList) String.join(java.lang.String.join) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MIN_PAGE_SIZE_IN_BYTES(com.facebook.presto.operator.project.PageProcessor.MIN_PAGE_SIZE_IN_BYTES) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) SelectedPositions.positionsRange(com.facebook.presto.operator.project.SelectedPositions.positionsRange) ArrayType(com.facebook.presto.common.type.ArrayType) AggregatedMemoryContext.newSimpleAggregatedMemoryContext(com.facebook.presto.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext) MAX_PAGE_SIZE_IN_BYTES(com.facebook.presto.operator.project.PageProcessor.MAX_PAGE_SIZE_IN_BYTES) Type(com.facebook.presto.common.type.Type) BlockAssertions.createLongSequenceBlock(com.facebook.presto.block.BlockAssertions.createLongSequenceBlock) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) PageAssertions.createPageWithRandomData(com.facebook.presto.operator.PageAssertions.createPageWithRandomData) BlockAssertions.createMapType(com.facebook.presto.block.BlockAssertions.createMapType) Iterator(java.util.Iterator) BlockAssertions.createStringsBlock(com.facebook.presto.block.BlockAssertions.createStringsBlock) AggregatedMemoryContext(com.facebook.presto.memory.context.AggregatedMemoryContext) SelectedPositions.positionsList(com.facebook.presto.operator.project.SelectedPositions.positionsList) MetadataManager.createTestMetadataManager(com.facebook.presto.metadata.MetadataManager.createTestMetadataManager) Work(com.facebook.presto.operator.Work) Assert.assertTrue(org.testng.Assert.assertTrue) ExpressionProfiler(com.facebook.presto.sql.gen.ExpressionProfiler) Block(com.facebook.presto.common.block.Block) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext) LazyBlock(com.facebook.presto.common.block.LazyBlock) Optional(java.util.Optional) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) Test(org.testng.annotations.Test)

Example 14 with LocalMemoryContext

use of com.facebook.presto.memory.context.LocalMemoryContext in project presto by prestodb.

the class OutputBufferMemoryManager method updateMemoryUsage.

public void updateMemoryUsage(long bytesAdded) {
    LocalMemoryContext systemMemoryContext = getSystemMemoryContextOrNull();
    if (systemMemoryContext == null) {
        // aborted, so we can just return (see the comment in getSystemMemoryContextOrNull()).
        return;
    }
    ListenableFuture<?> waitForMemory = null;
    SettableFuture<?> notifyUnblocked = null;
    long currentBufferedBytes;
    synchronized (this) {
        // we can also safely ignore any calls after OutputBufferMemoryManager is closed.
        if (closed) {
            return;
        }
        currentBufferedBytes = bufferedBytes.addAndGet(bytesAdded);
        ListenableFuture<?> blockedOnMemory = systemMemoryContext.setBytes(currentBufferedBytes);
        if (!blockedOnMemory.isDone()) {
            if (this.blockedOnMemory != blockedOnMemory) {
                this.blockedOnMemory = blockedOnMemory;
                // only register a callback when blocked and the future is different
                waitForMemory = blockedOnMemory;
            }
        } else {
            this.blockedOnMemory = NOT_BLOCKED;
            if (currentBufferedBytes <= maxBufferedBytes || !blockOnFull.get()) {
                // Complete future in a new thread to avoid making a callback on the caller thread.
                // This make is easier for callers to use this class since they can update the memory
                // usage while holding locks.
                notifyUnblocked = this.bufferBlockedFuture;
                this.bufferBlockedFuture = null;
            }
        }
    }
    peakMemoryUsage.accumulateAndGet(currentBufferedBytes, Math::max);
    // Notify listeners outside of the critical section
    notifyListener(notifyUnblocked);
    if (waitForMemory != null) {
        waitForMemory.addListener(this::onMemoryAvailable, notificationExecutor);
    }
}
Also used : LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext)

Example 15 with LocalMemoryContext

use of com.facebook.presto.memory.context.LocalMemoryContext in project presto by prestodb.

the class OutputBufferMemoryManager method close.

public synchronized void close() {
    updateMemoryUsage(-bufferedBytes.get());
    LocalMemoryContext memoryContext = getSystemMemoryContextOrNull();
    if (memoryContext != null) {
        memoryContext.close();
    }
    closed = true;
}
Also used : LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext)

Aggregations

LocalMemoryContext (com.facebook.presto.memory.context.LocalMemoryContext)31 Test (org.testng.annotations.Test)23 Page (com.facebook.presto.common.Page)8 QueryId (com.facebook.presto.spi.QueryId)6 Optional (java.util.Optional)6 DriverYieldSignal (com.facebook.presto.operator.DriverYieldSignal)5 Block (com.facebook.presto.common.block.Block)3 Type (com.facebook.presto.common.type.Type)3 DriverContext (com.facebook.presto.operator.DriverContext)3 OperatorContext (com.facebook.presto.operator.OperatorContext)3 Slice (io.airlift.slice.Slice)3 List (java.util.List)3 Supplier (java.util.function.Supplier)3 ClassLayout (org.openjdk.jol.info.ClassLayout)3 Threads.daemonThreadsNamed (com.facebook.airlift.concurrent.Threads.daemonThreadsNamed)2 TestingTicker (com.facebook.airlift.testing.TestingTicker)2 ExceededMemoryLimitException (com.facebook.presto.ExceededMemoryLimitException)2 BlockAssertions (com.facebook.presto.block.BlockAssertions)2 BlockAssertions.createLongSequenceBlock (com.facebook.presto.block.BlockAssertions.createLongSequenceBlock)2 BlockAssertions.createMapType (com.facebook.presto.block.BlockAssertions.createMapType)2