Search in sources :

Example 6 with NetworkSequenceViewReader

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

the class PartitionRequestQueueTest method testEnqueueReaderByNotifyingEventBuffer.

/**
 * Tests {@link PartitionRequestQueue#enqueueAvailableReader(NetworkSequenceViewReader)},
 * verifying the reader would be enqueued in the pipeline if the next sending buffer is an event
 * even though it has no available credits.
 */
@Test
public void testEnqueueReaderByNotifyingEventBuffer() throws Exception {
    // setup
    final ResultSubpartitionView view = new NextIsEventResultSubpartitionView();
    ResultPartitionProvider partitionProvider = (partitionId, index, availabilityListener) -> view;
    final InputChannelID receiverId = new InputChannelID();
    final PartitionRequestQueue queue = new PartitionRequestQueue();
    final CreditBasedSequenceNumberingViewReader reader = new CreditBasedSequenceNumberingViewReader(receiverId, 0, queue);
    final EmbeddedChannel channel = new EmbeddedChannel(queue);
    reader.requestSubpartitionView(partitionProvider, new ResultPartitionID(), 0);
    // block the channel so that we see an intermediate state in the test
    ByteBuf channelBlockingBuffer = blockChannel(channel);
    assertNull(channel.readOutbound());
    // Notify an available event buffer to trigger enqueue the reader
    reader.notifyDataAvailable();
    channel.runPendingTasks();
    // The reader is enqueued in the pipeline because the next buffer is an event, even though
    // no credits are available
    // contains only (this) one!
    assertThat(queue.getAvailableReaders(), contains(reader));
    assertEquals(0, reader.getNumCreditsAvailable());
    // Flush the buffer to make the channel writable again and see the final results
    channel.flush();
    assertSame(channelBlockingBuffer, channel.readOutbound());
    assertEquals(0, queue.getAvailableReaders().size());
    assertEquals(0, reader.getNumCreditsAvailable());
    assertNull(channel.readOutbound());
}
Also used : BufferAndBacklog(org.apache.flink.runtime.io.network.partition.ResultSubpartition.BufferAndBacklog) TestBufferFactory(org.apache.flink.runtime.io.network.util.TestBufferFactory) BeforeClass(org.junit.BeforeClass) ResultPartitionType(org.apache.flink.runtime.io.network.partition.ResultPartitionType) ByteBuffer(java.nio.ByteBuffer) FileChannelManager(org.apache.flink.runtime.io.disk.FileChannelManager) NetworkSequenceViewReader(org.apache.flink.runtime.io.network.NetworkSequenceViewReader) ResultPartition(org.apache.flink.runtime.io.network.partition.ResultPartition) Assert.assertSame(org.junit.Assert.assertSame) Assert.assertThat(org.junit.Assert.assertThat) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BufferAvailabilityListener(org.apache.flink.runtime.io.network.partition.BufferAvailabilityListener) BufferBuilderTestUtils.createEventBufferConsumer(org.apache.flink.runtime.io.network.buffer.BufferBuilderTestUtils.createEventBufferConsumer) ClassRule(org.junit.ClassRule) Nullable(javax.annotation.Nullable) NoOpResultSubpartitionView(org.apache.flink.runtime.io.network.partition.NoOpResultSubpartitionView) AfterClass(org.junit.AfterClass) PipelinedSubpartitionView(org.apache.flink.runtime.io.network.partition.PipelinedSubpartitionView) NettyShuffleEnvironmentBuilder(org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder) Assert.assertNotNull(org.junit.Assert.assertNotNull) Unpooled(org.apache.flink.shaded.netty4.io.netty.buffer.Unpooled) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) NettyShuffleEnvironment(org.apache.flink.runtime.io.network.NettyShuffleEnvironment) ByteBuf(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) NoOpBufferAvailablityListener(org.apache.flink.runtime.io.network.partition.NoOpBufferAvailablityListener) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) PipelinedSubpartition(org.apache.flink.runtime.io.network.partition.PipelinedSubpartition) Assert.assertNull(org.junit.Assert.assertNull) Matchers.contains(org.hamcrest.Matchers.contains) Assert.assertFalse(org.junit.Assert.assertFalse) NoOpFileChannelManager(org.apache.flink.runtime.io.disk.NoOpFileChannelManager) PipelinedSubpartitionTest(org.apache.flink.runtime.io.network.partition.PipelinedSubpartitionTest) FileChannelManagerImpl(org.apache.flink.runtime.io.disk.FileChannelManagerImpl) ResultPartitionManager(org.apache.flink.runtime.io.network.partition.ResultPartitionManager) ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) EmbeddedChannel(org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel) PartitionTestUtils.createPartition(org.apache.flink.runtime.io.network.partition.PartitionTestUtils.createPartition) ResultPartitionProvider(org.apache.flink.runtime.io.network.partition.ResultPartitionProvider) InputChannelID(org.apache.flink.runtime.io.network.partition.consumer.InputChannelID) TemporaryFolder(org.junit.rules.TemporaryFolder) Assert.assertEquals(org.junit.Assert.assertEquals) NoOpResultSubpartitionView(org.apache.flink.runtime.io.network.partition.NoOpResultSubpartitionView) ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) InputChannelID(org.apache.flink.runtime.io.network.partition.consumer.InputChannelID) EmbeddedChannel(org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) ResultPartitionProvider(org.apache.flink.runtime.io.network.partition.ResultPartitionProvider) ByteBuf(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf) Test(org.junit.Test) PipelinedSubpartitionTest(org.apache.flink.runtime.io.network.partition.PipelinedSubpartitionTest)

Example 7 with NetworkSequenceViewReader

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

the class PartitionRequestQueueTest method testEnqueueReaderByResumingConsumption.

/**
 * Tests {@link PartitionRequestQueue#enqueueAvailableReader(NetworkSequenceViewReader)},
 * verifying the reader would be enqueued in the pipeline after resuming data consumption if
 * there are credit and data available.
 */
@Test
public void testEnqueueReaderByResumingConsumption() throws Exception {
    PipelinedSubpartition subpartition = PipelinedSubpartitionTest.createPipelinedSubpartition();
    Buffer.DataType dataType1 = Buffer.DataType.ALIGNED_CHECKPOINT_BARRIER;
    Buffer.DataType dataType2 = Buffer.DataType.DATA_BUFFER;
    subpartition.add(createEventBufferConsumer(4096, dataType1));
    subpartition.add(createEventBufferConsumer(4096, dataType2));
    BufferAvailabilityListener bufferAvailabilityListener = new NoOpBufferAvailablityListener();
    PipelinedSubpartitionView view = subpartition.createReadView(bufferAvailabilityListener);
    ResultPartitionProvider partitionProvider = (partitionId, index, availabilityListener) -> view;
    InputChannelID receiverId = new InputChannelID();
    PartitionRequestQueue queue = new PartitionRequestQueue();
    CreditBasedSequenceNumberingViewReader reader = new CreditBasedSequenceNumberingViewReader(receiverId, 2, queue);
    EmbeddedChannel channel = new EmbeddedChannel(queue);
    reader.requestSubpartitionView(partitionProvider, new ResultPartitionID(), 0);
    queue.notifyReaderCreated(reader);
    assertTrue(reader.getAvailabilityAndBacklog().isAvailable());
    reader.notifyDataAvailable();
    channel.runPendingTasks();
    assertFalse(reader.getAvailabilityAndBacklog().isAvailable());
    assertEquals(1, subpartition.unsynchronizedGetNumberOfQueuedBuffers());
    queue.addCreditOrResumeConsumption(receiverId, NetworkSequenceViewReader::resumeConsumption);
    assertFalse(reader.getAvailabilityAndBacklog().isAvailable());
    assertEquals(0, subpartition.unsynchronizedGetNumberOfQueuedBuffers());
    Object data1 = channel.readOutbound();
    assertEquals(dataType1, ((NettyMessage.BufferResponse) data1).buffer.getDataType());
    Object data2 = channel.readOutbound();
    assertEquals(dataType2, ((NettyMessage.BufferResponse) data2).buffer.getDataType());
}
Also used : ByteBuffer(java.nio.ByteBuffer) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) BufferAndBacklog(org.apache.flink.runtime.io.network.partition.ResultSubpartition.BufferAndBacklog) TestBufferFactory(org.apache.flink.runtime.io.network.util.TestBufferFactory) BeforeClass(org.junit.BeforeClass) ResultPartitionType(org.apache.flink.runtime.io.network.partition.ResultPartitionType) ByteBuffer(java.nio.ByteBuffer) FileChannelManager(org.apache.flink.runtime.io.disk.FileChannelManager) NetworkSequenceViewReader(org.apache.flink.runtime.io.network.NetworkSequenceViewReader) ResultPartition(org.apache.flink.runtime.io.network.partition.ResultPartition) Assert.assertSame(org.junit.Assert.assertSame) Assert.assertThat(org.junit.Assert.assertThat) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BufferAvailabilityListener(org.apache.flink.runtime.io.network.partition.BufferAvailabilityListener) BufferBuilderTestUtils.createEventBufferConsumer(org.apache.flink.runtime.io.network.buffer.BufferBuilderTestUtils.createEventBufferConsumer) ClassRule(org.junit.ClassRule) Nullable(javax.annotation.Nullable) NoOpResultSubpartitionView(org.apache.flink.runtime.io.network.partition.NoOpResultSubpartitionView) AfterClass(org.junit.AfterClass) PipelinedSubpartitionView(org.apache.flink.runtime.io.network.partition.PipelinedSubpartitionView) NettyShuffleEnvironmentBuilder(org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder) Assert.assertNotNull(org.junit.Assert.assertNotNull) Unpooled(org.apache.flink.shaded.netty4.io.netty.buffer.Unpooled) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) NettyShuffleEnvironment(org.apache.flink.runtime.io.network.NettyShuffleEnvironment) ByteBuf(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) NoOpBufferAvailablityListener(org.apache.flink.runtime.io.network.partition.NoOpBufferAvailablityListener) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) PipelinedSubpartition(org.apache.flink.runtime.io.network.partition.PipelinedSubpartition) Assert.assertNull(org.junit.Assert.assertNull) Matchers.contains(org.hamcrest.Matchers.contains) Assert.assertFalse(org.junit.Assert.assertFalse) NoOpFileChannelManager(org.apache.flink.runtime.io.disk.NoOpFileChannelManager) PipelinedSubpartitionTest(org.apache.flink.runtime.io.network.partition.PipelinedSubpartitionTest) FileChannelManagerImpl(org.apache.flink.runtime.io.disk.FileChannelManagerImpl) ResultPartitionManager(org.apache.flink.runtime.io.network.partition.ResultPartitionManager) ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) EmbeddedChannel(org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel) PartitionTestUtils.createPartition(org.apache.flink.runtime.io.network.partition.PartitionTestUtils.createPartition) ResultPartitionProvider(org.apache.flink.runtime.io.network.partition.ResultPartitionProvider) InputChannelID(org.apache.flink.runtime.io.network.partition.consumer.InputChannelID) TemporaryFolder(org.junit.rules.TemporaryFolder) Assert.assertEquals(org.junit.Assert.assertEquals) PipelinedSubpartition(org.apache.flink.runtime.io.network.partition.PipelinedSubpartition) EmbeddedChannel(org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel) PipelinedSubpartitionView(org.apache.flink.runtime.io.network.partition.PipelinedSubpartitionView) InputChannelID(org.apache.flink.runtime.io.network.partition.consumer.InputChannelID) BufferAvailabilityListener(org.apache.flink.runtime.io.network.partition.BufferAvailabilityListener) NoOpBufferAvailablityListener(org.apache.flink.runtime.io.network.partition.NoOpBufferAvailablityListener) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) NetworkSequenceViewReader(org.apache.flink.runtime.io.network.NetworkSequenceViewReader) ResultPartitionProvider(org.apache.flink.runtime.io.network.partition.ResultPartitionProvider) Test(org.junit.Test) PipelinedSubpartitionTest(org.apache.flink.runtime.io.network.partition.PipelinedSubpartitionTest)

Example 8 with NetworkSequenceViewReader

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

the class PartitionRequestServerHandlerTest method testAcknowledgeAllRecordsProcessed.

@Test
public void testAcknowledgeAllRecordsProcessed() throws IOException {
    InputChannelID inputChannelID = new InputChannelID();
    ResultPartition resultPartition = PartitionTestUtils.createPartition(ResultPartitionType.PIPELINED_BOUNDED);
    ResultPartitionProvider partitionProvider = (partitionId, index, availabilityListener) -> resultPartition.createSubpartitionView(index, availabilityListener);
    // Creates the netty network handler stack.
    PartitionRequestQueue partitionRequestQueue = new PartitionRequestQueue();
    final PartitionRequestServerHandler serverHandler = new PartitionRequestServerHandler(new ResultPartitionManager(), new TaskEventDispatcher(), partitionRequestQueue);
    final EmbeddedChannel channel = new EmbeddedChannel(serverHandler, partitionRequestQueue);
    // Creates and registers the view to netty.
    NetworkSequenceViewReader viewReader = new CreditBasedSequenceNumberingViewReader(inputChannelID, 2, partitionRequestQueue);
    viewReader.requestSubpartitionView(partitionProvider, resultPartition.getPartitionId(), 0);
    partitionRequestQueue.notifyReaderCreated(viewReader);
    // Write the message to acknowledge all records are processed to server
    resultPartition.notifyEndOfData(StopMode.DRAIN);
    CompletableFuture<Void> allRecordsProcessedFuture = resultPartition.getAllDataProcessedFuture();
    assertFalse(allRecordsProcessedFuture.isDone());
    channel.writeInbound(new NettyMessage.AckAllUserRecordsProcessed(inputChannelID));
    channel.runPendingTasks();
    assertTrue(allRecordsProcessedFuture.isDone());
    assertFalse(allRecordsProcessedFuture.isCompletedExceptionally());
}
Also used : PartitionRequest(org.apache.flink.runtime.io.network.netty.NettyMessage.PartitionRequest) ResultPartitionType(org.apache.flink.runtime.io.network.partition.ResultPartitionType) CompletableFuture(java.util.concurrent.CompletableFuture) NetworkSequenceViewReader(org.apache.flink.runtime.io.network.NetworkSequenceViewReader) ResultPartition(org.apache.flink.runtime.io.network.partition.ResultPartition) Assert.assertThat(org.junit.Assert.assertThat) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) ErrorResponse(org.apache.flink.runtime.io.network.netty.NettyMessage.ErrorResponse) TestLogger(org.apache.flink.util.TestLogger) TaskEventDispatcher(org.apache.flink.runtime.io.network.TaskEventDispatcher) Assert.assertTrue(org.junit.Assert.assertTrue) ResumeConsumption(org.apache.flink.runtime.io.network.netty.NettyMessage.ResumeConsumption) Test(org.junit.Test) IOException(java.io.IOException) PartitionNotFoundException(org.apache.flink.runtime.io.network.partition.PartitionNotFoundException) StopMode(org.apache.flink.runtime.io.network.api.StopMode) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Assert.assertFalse(org.junit.Assert.assertFalse) PartitionTestUtils(org.apache.flink.runtime.io.network.partition.PartitionTestUtils) Matchers.is(org.hamcrest.Matchers.is) ResultPartitionManager(org.apache.flink.runtime.io.network.partition.ResultPartitionManager) EmbeddedChannel(org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel) ResultPartitionProvider(org.apache.flink.runtime.io.network.partition.ResultPartitionProvider) InputChannelID(org.apache.flink.runtime.io.network.partition.consumer.InputChannelID) Assert.assertEquals(org.junit.Assert.assertEquals) EmbeddedChannel(org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel) ResultPartitionManager(org.apache.flink.runtime.io.network.partition.ResultPartitionManager) ResultPartition(org.apache.flink.runtime.io.network.partition.ResultPartition) InputChannelID(org.apache.flink.runtime.io.network.partition.consumer.InputChannelID) NetworkSequenceViewReader(org.apache.flink.runtime.io.network.NetworkSequenceViewReader) ResultPartitionProvider(org.apache.flink.runtime.io.network.partition.ResultPartitionProvider) TaskEventDispatcher(org.apache.flink.runtime.io.network.TaskEventDispatcher) Test(org.junit.Test)

Aggregations

NetworkSequenceViewReader (org.apache.flink.runtime.io.network.NetworkSequenceViewReader)8 IOException (java.io.IOException)5 ResultPartition (org.apache.flink.runtime.io.network.partition.ResultPartition)4 ResultPartitionID (org.apache.flink.runtime.io.network.partition.ResultPartitionID)4 ResultPartitionManager (org.apache.flink.runtime.io.network.partition.ResultPartitionManager)4 ResultPartitionProvider (org.apache.flink.runtime.io.network.partition.ResultPartitionProvider)4 ResultPartitionType (org.apache.flink.runtime.io.network.partition.ResultPartitionType)4 InputChannelID (org.apache.flink.runtime.io.network.partition.consumer.InputChannelID)4 EmbeddedChannel (org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel)4 ByteBuffer (java.nio.ByteBuffer)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Nullable (javax.annotation.Nullable)3 FileChannelManager (org.apache.flink.runtime.io.disk.FileChannelManager)3 FileChannelManagerImpl (org.apache.flink.runtime.io.disk.FileChannelManagerImpl)3 NoOpFileChannelManager (org.apache.flink.runtime.io.disk.NoOpFileChannelManager)3 NettyShuffleEnvironment (org.apache.flink.runtime.io.network.NettyShuffleEnvironment)3 NettyShuffleEnvironmentBuilder (org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder)3 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)3 BufferBuilderTestUtils.createEventBufferConsumer (org.apache.flink.runtime.io.network.buffer.BufferBuilderTestUtils.createEventBufferConsumer)3 BufferAvailabilityListener (org.apache.flink.runtime.io.network.partition.BufferAvailabilityListener)3