Search in sources :

Example 21 with ResultSubpartitionView

use of org.apache.flink.runtime.io.network.partition.ResultSubpartitionView in project flink by apache.

the class LocalInputChannelTest method testGetBufferFromLocalChannelWhenCompressionEnabled.

/**
 * Verifies that buffer is not compressed when getting from a {@link LocalInputChannel}.
 */
@Test
public void testGetBufferFromLocalChannelWhenCompressionEnabled() throws Exception {
    ResultSubpartitionView subpartitionView = InputChannelTestUtils.createResultSubpartitionView(true);
    TestingResultPartitionManager partitionManager = new TestingResultPartitionManager(subpartitionView);
    LocalInputChannel channel = createLocalInputChannel(new SingleInputGateBuilder().build(), partitionManager);
    // request partition and get next buffer
    channel.requestSubpartition();
    Optional<InputChannel.BufferAndAvailability> bufferAndAvailability = channel.getNextBuffer();
    assertTrue(bufferAndAvailability.isPresent());
    assertFalse(bufferAndAvailability.get().buffer().isCompressed());
}
Also used : ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) InputChannelTestUtils.createLocalInputChannel(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createLocalInputChannel) TestingResultPartitionManager(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateTest.TestingResultPartitionManager) Test(org.junit.Test)

Example 22 with ResultSubpartitionView

use of org.apache.flink.runtime.io.network.partition.ResultSubpartitionView in project flink by apache.

the class PartitionRequestQueueTest method testProducerFailedException.

@Test
public void testProducerFailedException() throws Exception {
    PartitionRequestQueue queue = new PartitionRequestQueue();
    ResultPartitionProvider partitionProvider = mock(ResultPartitionProvider.class);
    ResultPartitionID rpid = new ResultPartitionID();
    BufferProvider bufferProvider = mock(BufferProvider.class);
    ResultSubpartitionView view = mock(ResultSubpartitionView.class);
    when(view.isReleased()).thenReturn(true);
    when(view.getFailureCause()).thenReturn(new RuntimeException("Expected test exception"));
    when(partitionProvider.createSubpartitionView(eq(rpid), eq(0), eq(bufferProvider), any(BufferAvailabilityListener.class))).thenReturn(view);
    EmbeddedChannel ch = new EmbeddedChannel(queue);
    SequenceNumberingViewReader seqView = new SequenceNumberingViewReader(new InputChannelID(), queue);
    seqView.requestSubpartitionView(partitionProvider, rpid, 0, bufferProvider);
    // Enqueue the erroneous view
    queue.notifyReaderNonEmpty(seqView);
    ch.runPendingTasks();
    // Read the enqueued msg
    Object msg = ch.readOutbound();
    assertEquals(msg.getClass(), NettyMessage.ErrorResponse.class);
    NettyMessage.ErrorResponse err = (NettyMessage.ErrorResponse) msg;
    assertTrue(err.cause instanceof CancelTaskException);
}
Also used : ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) InputChannelID(org.apache.flink.runtime.io.network.partition.consumer.InputChannelID) BufferAvailabilityListener(org.apache.flink.runtime.io.network.partition.BufferAvailabilityListener) BufferProvider(org.apache.flink.runtime.io.network.buffer.BufferProvider) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) ResultPartitionProvider(org.apache.flink.runtime.io.network.partition.ResultPartitionProvider) Test(org.junit.Test)

Example 23 with ResultSubpartitionView

use of org.apache.flink.runtime.io.network.partition.ResultSubpartitionView in project flink by apache.

the class LocalInputChannelTest method testEnqueueAvailableChannelWhenResuming.

@Test
public void testEnqueueAvailableChannelWhenResuming() throws IOException, InterruptedException {
    PipelinedResultPartition parent = (PipelinedResultPartition) PartitionTestUtils.createPartition(ResultPartitionType.PIPELINED, NoOpFileChannelManager.INSTANCE);
    ResultSubpartition subpartition = parent.getAllPartitions()[0];
    ResultSubpartitionView subpartitionView = subpartition.createReadView(() -> {
    });
    TestingResultPartitionManager partitionManager = new TestingResultPartitionManager(subpartitionView);
    LocalInputChannel channel = createLocalInputChannel(new SingleInputGateBuilder().build(), partitionManager);
    channel.requestSubpartition();
    // Block the subpartition
    subpartition.add(EventSerializer.toBufferConsumer(new CheckpointBarrier(1, 1, CheckpointOptions.forCheckpointWithDefaultLocation()), false));
    assertTrue(channel.getNextBuffer().isPresent());
    // Add more data
    subpartition.add(createFilledFinishedBufferConsumer(4096));
    subpartition.flush();
    // No buffer since the subpartition is blocked.
    assertFalse(channel.inputGate.pollNext().isPresent());
    // Resumption makes the subpartition available.
    channel.resumeConsumption();
    Optional<BufferOrEvent> nextBuffer = channel.inputGate.pollNext();
    assertTrue(nextBuffer.isPresent());
    assertTrue(nextBuffer.get().isBuffer());
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) PipelinedResultPartition(org.apache.flink.runtime.io.network.partition.PipelinedResultPartition) ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) ResultSubpartition(org.apache.flink.runtime.io.network.partition.ResultSubpartition) InputChannelTestUtils.createLocalInputChannel(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createLocalInputChannel) TestingResultPartitionManager(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateTest.TestingResultPartitionManager) Test(org.junit.Test)

Example 24 with ResultSubpartitionView

use of org.apache.flink.runtime.io.network.partition.ResultSubpartitionView 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)

Example 25 with ResultSubpartitionView

use of org.apache.flink.runtime.io.network.partition.ResultSubpartitionView in project flink by apache.

the class LocalInputChannel method resumeConsumption.

@Override
public void resumeConsumption() {
    checkState(!isReleased, "Channel released.");
    ResultSubpartitionView subpartitionView = checkNotNull(this.subpartitionView);
    subpartitionView.resumeConsumption();
    if (subpartitionView.getAvailabilityAndBacklog(Integer.MAX_VALUE).isAvailable()) {
        notifyChannelNonEmpty();
    }
}
Also used : ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView)

Aggregations

ResultSubpartitionView (org.apache.flink.runtime.io.network.partition.ResultSubpartitionView)32 Test (org.junit.Test)22 NoOpBufferAvailablityListener (org.apache.flink.runtime.io.network.partition.NoOpBufferAvailablityListener)15 ResultPartition (org.apache.flink.runtime.io.network.partition.ResultPartition)13 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)12 BufferAvailabilityListener (org.apache.flink.runtime.io.network.partition.BufferAvailabilityListener)10 ResultPartitionID (org.apache.flink.runtime.io.network.partition.ResultPartitionID)10 IOException (java.io.IOException)9 ResultPartitionManager (org.apache.flink.runtime.io.network.partition.ResultPartitionManager)9 InputChannelID (org.apache.flink.runtime.io.network.partition.consumer.InputChannelID)8 InputChannelTestUtils.createLocalInputChannel (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createLocalInputChannel)6 BufferAndBacklog (org.apache.flink.runtime.io.network.partition.ResultSubpartition.BufferAndBacklog)6 TestingResultPartitionManager (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateTest.TestingResultPartitionManager)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 CancelTaskException (org.apache.flink.runtime.execution.CancelTaskException)5 NoOpFileChannelManager (org.apache.flink.runtime.io.disk.NoOpFileChannelManager)5 CheckpointBarrier (org.apache.flink.runtime.io.network.api.CheckpointBarrier)5 ResultPartitionType (org.apache.flink.runtime.io.network.partition.ResultPartitionType)5 TestBufferFactory (org.apache.flink.runtime.io.network.util.TestBufferFactory)5 ByteBuffer (java.nio.ByteBuffer)4