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