Search in sources :

Example 1 with FileRegionBuffer

use of org.apache.flink.runtime.io.network.buffer.FileRegionBuffer in project flink by apache.

the class LocalInputChannel method getNextBuffer.

@Override
Optional<BufferAndAvailability> getNextBuffer() throws IOException {
    checkError();
    ResultSubpartitionView subpartitionView = this.subpartitionView;
    if (subpartitionView == null) {
        // during) it was released during reading the EndOfPartitionEvent (2).
        if (isReleased) {
            return Optional.empty();
        }
        // this can happen if the request for the partition was triggered asynchronously
        // by the time trigger
        // would be good to avoid that, by guaranteeing that the requestPartition() and
        // getNextBuffer() always come from the same thread
        // we could do that by letting the timer insert a special "requesting channel" into the
        // input gate's queue
        subpartitionView = checkAndWaitForSubpartitionView();
    }
    BufferAndBacklog next = subpartitionView.getNextBuffer();
    // ignore the empty buffer directly
    while (next != null && next.buffer().readableBytes() == 0) {
        next.buffer().recycleBuffer();
        next = subpartitionView.getNextBuffer();
        numBuffersIn.inc();
    }
    if (next == null) {
        if (subpartitionView.isReleased()) {
            throw new CancelTaskException("Consumed partition " + subpartitionView + " has been released.");
        } else {
            return Optional.empty();
        }
    }
    Buffer buffer = next.buffer();
    if (buffer instanceof FileRegionBuffer) {
        buffer = ((FileRegionBuffer) buffer).readInto(inputGate.getUnpooledSegment());
    }
    numBytesIn.inc(buffer.getSize());
    numBuffersIn.inc();
    channelStatePersister.checkForBarrier(buffer);
    channelStatePersister.maybePersist(buffer);
    NetworkActionsLogger.traceInput("LocalInputChannel#getNextBuffer", buffer, inputGate.getOwningTaskName(), channelInfo, channelStatePersister, next.getSequenceNumber());
    return Optional.of(new BufferAndAvailability(buffer, next.getNextDataType(), next.buffersInBacklog(), next.getSequenceNumber()));
}
Also used : FileRegionBuffer(org.apache.flink.runtime.io.network.buffer.FileRegionBuffer) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) FileRegionBuffer(org.apache.flink.runtime.io.network.buffer.FileRegionBuffer) ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) BufferAndBacklog(org.apache.flink.runtime.io.network.partition.ResultSubpartition.BufferAndBacklog)

Aggregations

CancelTaskException (org.apache.flink.runtime.execution.CancelTaskException)1 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)1 FileRegionBuffer (org.apache.flink.runtime.io.network.buffer.FileRegionBuffer)1 BufferAndBacklog (org.apache.flink.runtime.io.network.partition.ResultSubpartition.BufferAndBacklog)1 ResultSubpartitionView (org.apache.flink.runtime.io.network.partition.ResultSubpartitionView)1