Search in sources :

Example 6 with SerializedPage

use of com.facebook.presto.spi.page.SerializedPage in project presto by prestodb.

the class ExchangeClient method addPages.

private boolean addPages(List<SerializedPage> pages) {
    // Compute stats before acquiring the lock
    long pagesRetainedSizeInBytes = 0;
    long responseSize = 0;
    for (SerializedPage page : pages) {
        pagesRetainedSizeInBytes += page.getRetainedSizeInBytes();
        responseSize += page.getSizeInBytes();
    }
    List<SettableFuture<?>> notify = ImmutableList.of();
    synchronized (this) {
        if (isClosed() || isFailed()) {
            return false;
        }
        if (!pages.isEmpty()) {
            pageBuffer.addAll(pages);
            bufferRetainedSizeInBytes += pagesRetainedSizeInBytes;
            maxBufferRetainedSizeInBytes = max(maxBufferRetainedSizeInBytes, bufferRetainedSizeInBytes);
            systemMemoryContext.setBytes(bufferRetainedSizeInBytes);
            // Notify pending listeners that a page has been added
            notify = ImmutableList.copyOf(blockedCallers);
            blockedCallers.clear();
        }
        successfulRequests++;
        responseSizeExponentialMovingAverage.update(responseSize);
    }
    // Trigger notifications after releasing the lock
    notifyListeners(notify);
    return true;
}
Also used : SettableFuture(com.google.common.util.concurrent.SettableFuture) SerializedPage(com.facebook.presto.spi.page.SerializedPage)

Example 7 with SerializedPage

use of com.facebook.presto.spi.page.SerializedPage in project presto by prestodb.

the class PartitionedOutputBuffer method enqueue.

@Override
public void enqueue(Lifespan lifespan, int partitionNumber, List<SerializedPage> pages) {
    requireNonNull(lifespan, "lifespan is null");
    requireNonNull(pages, "pages is null");
    checkState(pageTracker.isLifespanCompletionCallbackRegistered(), "lifespanCompletionCallback must be set before enqueueing data");
    // this can happen with a limit query
    if (!state.get().canAddPages() || pageTracker.isNoMorePagesForLifespan(lifespan)) {
        return;
    }
    ImmutableList.Builder<SerializedPageReference> references = ImmutableList.builderWithExpectedSize(pages.size());
    long bytesAdded = 0;
    long rowCount = 0;
    for (SerializedPage page : pages) {
        long retainedSize = page.getRetainedSizeInBytes();
        bytesAdded += retainedSize;
        rowCount += page.getPositionCount();
        // create page reference counts with an initial single reference
        references.add(new SerializedPageReference(page, 1, lifespan));
    }
    List<SerializedPageReference> serializedPageReferences = references.build();
    // reserve memory
    memoryManager.updateMemoryUsage(bytesAdded);
    // update stats
    totalRowsAdded.addAndGet(rowCount);
    totalPagesAdded.addAndGet(serializedPageReferences.size());
    pageTracker.incrementLifespanPageCount(lifespan, serializedPageReferences.size());
    // add pages to the buffer (this will increase the reference count by one)
    partitions.get(partitionNumber).enqueuePages(serializedPageReferences);
    // drop the initial reference
    dereferencePages(serializedPageReferences, pageTracker);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) SerializedPage(com.facebook.presto.spi.page.SerializedPage)

Example 8 with SerializedPage

use of com.facebook.presto.spi.page.SerializedPage in project presto by prestodb.

the class SpoolingOutputBuffer method acknowledgePagesFromMemory.

private synchronized void acknowledgePagesFromMemory(long sequenceId, long startSequenceId) {
    checkState(startSequenceId == currentMemorySequenceId.get(), "Invalid startSequenceId for memory pages");
    int pagesToRemove = toIntExact(sequenceId - startSequenceId);
    checkArgument(pagesToRemove <= pages.size(), "Invalid sequenceId");
    long bytesRemoved = 0;
    for (int i = 0; i < pagesToRemove; i++) {
        SerializedPage removedPage = pages.remove();
        bytesRemoved += removedPage.getRetainedSizeInBytes();
        currentMemorySequenceId.incrementAndGet();
    }
    totalBufferedPages.addAndGet(-pagesToRemove);
    totalBufferedBytes.addAndGet(-bytesRemoved);
    totalInMemoryBytes.addAndGet(-bytesRemoved);
    totalPagesRemaining.addAndGet(-pagesToRemove);
}
Also used : SerializedPage(com.facebook.presto.spi.page.SerializedPage)

Example 9 with SerializedPage

use of com.facebook.presto.spi.page.SerializedPage in project presto by prestodb.

the class SpoolingOutputBuffer method getPagesFromMemory.

private List<SerializedPage> getPagesFromMemory(long startSequenceId, GetTracker getTracker) {
    checkArgument(startSequenceId == currentMemorySequenceId.get(), "Invalid startSequenceId for memory pages");
    checkArgument(getTracker.bytes < getTracker.maxSize.toBytes(), "bytesRead is greater than maxSize");
    ImmutableList.Builder<SerializedPage> result = ImmutableList.builder();
    List<SerializedPage> pages = getTracker.getMemoryPages();
    long maxBytes = getTracker.maxSize.toBytes();
    long bytes = 0;
    long pageCount = 0;
    for (SerializedPage page : pages) {
        bytes += page.getRetainedSizeInBytes();
        if (pageCount != 0 && bytes > maxBytes) {
            break;
        }
        result.add(page);
        pageCount++;
    }
    return result.build();
}
Also used : ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) SerializedPage(com.facebook.presto.spi.page.SerializedPage)

Example 10 with SerializedPage

use of com.facebook.presto.spi.page.SerializedPage in project presto by prestodb.

the class ArbitraryOutputBuffer method enqueue.

@Override
public void enqueue(Lifespan lifespan, List<SerializedPage> pages) {
    checkState(!Thread.holdsLock(this), "Can not enqueue pages while holding a lock on this");
    requireNonNull(lifespan, "lifespan is null");
    requireNonNull(pages, "page is null");
    checkState(pageTracker.isLifespanCompletionCallbackRegistered(), "lifespanCompletionCallback must be set before enqueueing data");
    // this can happen with a limit query
    if (!state.get().canAddPages() || pageTracker.isNoMorePagesForLifespan(lifespan)) {
        return;
    }
    ImmutableList.Builder<SerializedPageReference> references = ImmutableList.builderWithExpectedSize(pages.size());
    long bytesAdded = 0;
    long rowCount = 0;
    for (SerializedPage page : pages) {
        long retainedSize = page.getRetainedSizeInBytes();
        bytesAdded += retainedSize;
        rowCount += page.getPositionCount();
        // create page reference counts with an initial single reference
        references.add(new SerializedPageReference(page, 1, lifespan));
    }
    List<SerializedPageReference> serializedPageReferences = references.build();
    // reserve memory
    memoryManager.updateMemoryUsage(bytesAdded);
    // update stats
    totalRowsAdded.addAndGet(rowCount);
    totalPagesAdded.addAndGet(serializedPageReferences.size());
    pageTracker.incrementLifespanPageCount(lifespan, serializedPageReferences.size());
    // add pages to the buffer (this will increase the reference count by one)
    masterBuffer.addPages(serializedPageReferences);
    // process any pending reads from the client buffers
    List<ClientBuffer> buffers = safeGetBuffersSnapshot();
    if (buffers.isEmpty()) {
        return;
    }
    // handle potential for racy update of next index and client buffers present
    int index = nextClientBufferIndex.get() % buffers.size();
    for (int i = 0; i < buffers.size(); i++) {
        if (masterBuffer.isEmpty()) {
            // Resume from the current client buffer on the next iteration
            nextClientBufferIndex.set(index);
            break;
        }
        buffers.get(index).loadPagesIfNecessary(masterBuffer);
        index = (index + 1) % buffers.size();
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) SerializedPage(com.facebook.presto.spi.page.SerializedPage)

Aggregations

SerializedPage (com.facebook.presto.spi.page.SerializedPage)18 Page (com.facebook.presto.common.Page)8 ImmutableList (com.google.common.collect.ImmutableList)7 PrestoException (com.facebook.presto.spi.PrestoException)4 InputStreamSliceInput (io.airlift.slice.InputStreamSliceInput)4 InputStream (java.io.InputStream)3 List (java.util.List)3 BlockEncodingManager (com.facebook.presto.common.block.BlockEncodingManager)2 PagesSerde (com.facebook.presto.spi.page.PagesSerde)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 IOException (java.io.IOException)2 URI (java.net.URI)2 Test (org.testng.annotations.Test)2 BoundedExecutor (com.facebook.airlift.concurrent.BoundedExecutor)1 MoreFutures.addTimeout (com.facebook.airlift.concurrent.MoreFutures.addTimeout)1 APPLICATION_THRIFT_BINARY (com.facebook.airlift.http.client.thrift.ThriftRequestUtils.APPLICATION_THRIFT_BINARY)1 APPLICATION_THRIFT_COMPACT (com.facebook.airlift.http.client.thrift.ThriftRequestUtils.APPLICATION_THRIFT_COMPACT)1 APPLICATION_THRIFT_FB_COMPACT (com.facebook.airlift.http.client.thrift.ThriftRequestUtils.APPLICATION_THRIFT_FB_COMPACT)1 AsyncResponseHandler.bindAsyncResponse (com.facebook.airlift.http.server.AsyncResponseHandler.bindAsyncResponse)1 Codec (com.facebook.airlift.json.Codec)1