Search in sources :

Example 16 with ResultSubpartitionView

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

the class LocalInputChannelTest method testGetNextAfterPartitionReleased.

/**
 * Tests that reading from a channel when after the partition has been released are handled and
 * don't lead to NPEs.
 */
@Test
public void testGetNextAfterPartitionReleased() throws Exception {
    ResultSubpartitionView subpartitionView = InputChannelTestUtils.createResultSubpartitionView(false);
    TestingResultPartitionManager partitionManager = new TestingResultPartitionManager(subpartitionView);
    LocalInputChannel channel = createLocalInputChannel(new SingleInputGateBuilder().build(), partitionManager);
    channel.requestSubpartition();
    assertFalse(channel.getNextBuffer().isPresent());
    // release the subpartition view
    subpartitionView.releaseAllResources();
    try {
        channel.getNextBuffer();
        fail("Did not throw expected CancelTaskException");
    } catch (CancelTaskException ignored) {
    }
    channel.releaseAllResources();
    assertFalse(channel.getNextBuffer().isPresent());
}
Also used : ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) 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 17 with ResultSubpartitionView

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

the class LocalInputChannelTest method testReceivingBuffersInUseBeforeSubpartitionViewInitialization.

@Test
public void testReceivingBuffersInUseBeforeSubpartitionViewInitialization() throws Exception {
    // given: Local input channel without initialized subpartition view.
    ResultSubpartitionView subpartitionView = InputChannelTestUtils.createResultSubpartitionView(createFilledFinishedBufferConsumer(4096), createFilledFinishedBufferConsumer(4096), createFilledFinishedBufferConsumer(4096));
    TestingResultPartitionManager partitionManager = new TestingResultPartitionManager(subpartitionView);
    final SingleInputGate inputGate = createSingleInputGate(1);
    final LocalInputChannel localChannel = createLocalInputChannel(inputGate, partitionManager);
    inputGate.setInputChannels(localChannel);
    // then: Buffers in use should be equal to 0 until subpartition view initialization.
    assertEquals(0, localChannel.getBuffersInUseCount());
    // when: The subpartition view is initialized.
    localChannel.requestSubpartition();
    // then: Buffers in use should show correct value.
    assertEquals(3, localChannel.getBuffersInUseCount());
}
Also used : ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) InputChannelTestUtils.createLocalInputChannel(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createLocalInputChannel) InputChannelTestUtils.createSingleInputGate(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate) TestingResultPartitionManager(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateTest.TestingResultPartitionManager) Test(org.junit.Test)

Example 18 with ResultSubpartitionView

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

the class LocalInputChannelTest method testCheckpointingInflightData.

@Test
public void testCheckpointingInflightData() throws Exception {
    SingleInputGate inputGate = new SingleInputGateBuilder().build();
    PipelinedResultPartition parent = (PipelinedResultPartition) PartitionTestUtils.createPartition(ResultPartitionType.PIPELINED, NoOpFileChannelManager.INSTANCE);
    ResultSubpartition subpartition = parent.getAllPartitions()[0];
    ResultSubpartitionView subpartitionView = subpartition.createReadView(() -> {
    });
    TestingResultPartitionManager partitionManager = new TestingResultPartitionManager(subpartitionView);
    final RecordingChannelStateWriter stateWriter = new RecordingChannelStateWriter();
    LocalInputChannel channel = createLocalInputChannel(inputGate, partitionManager, 0, 0, b -> b.setStateWriter(stateWriter));
    inputGate.setInputChannels(channel);
    channel.requestSubpartition();
    final CheckpointStorageLocationReference location = getDefault();
    CheckpointOptions options = CheckpointOptions.unaligned(CheckpointType.CHECKPOINT, location);
    stateWriter.start(0, options);
    final CheckpointBarrier barrier = new CheckpointBarrier(0, 123L, options);
    channel.checkpointStarted(barrier);
    // add 1 buffer before barrier and 1 buffer afterwards. Only the first buffer should be
    // written.
    subpartition.add(createFilledFinishedBufferConsumer(1));
    assertTrue(channel.getNextBuffer().isPresent());
    subpartition.add(EventSerializer.toBufferConsumer(barrier, true));
    assertTrue(channel.getNextBuffer().isPresent());
    subpartition.add(createFilledFinishedBufferConsumer(2));
    assertTrue(channel.getNextBuffer().isPresent());
    assertArrayEquals(stateWriter.getAddedInput().get(channel.getChannelInfo()).stream().mapToInt(Buffer::getSize).toArray(), new int[] { 1 });
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) 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) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) RecordingChannelStateWriter(org.apache.flink.runtime.checkpoint.channel.RecordingChannelStateWriter) InputChannelTestUtils.createLocalInputChannel(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createLocalInputChannel) InputChannelTestUtils.createSingleInputGate(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate) TestingResultPartitionManager(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateTest.TestingResultPartitionManager) CheckpointStorageLocationReference(org.apache.flink.runtime.state.CheckpointStorageLocationReference) Test(org.junit.Test)

Example 19 with ResultSubpartitionView

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

the class LocalInputChannelTest method testProducerFailedException.

@Test(expected = CancelTaskException.class)
public void testProducerFailedException() throws Exception {
    ResultSubpartitionView view = mock(ResultSubpartitionView.class);
    when(view.isReleased()).thenReturn(true);
    when(view.getFailureCause()).thenReturn(new Exception("Expected test exception"));
    ResultPartitionManager partitionManager = mock(ResultPartitionManager.class);
    when(partitionManager.createSubpartitionView(any(ResultPartitionID.class), anyInt(), any(BufferAvailabilityListener.class))).thenReturn(view);
    SingleInputGate inputGate = mock(SingleInputGate.class);
    BufferProvider bufferProvider = mock(BufferProvider.class);
    when(inputGate.getBufferProvider()).thenReturn(bufferProvider);
    LocalInputChannel ch = createLocalInputChannel(inputGate, partitionManager);
    ch.requestSubpartition();
    // Should throw an instance of CancelTaskException.
    ch.getNextBuffer();
}
Also used : ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) 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) IntermediateResultPartitionID(org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID) ResultPartitionManager(org.apache.flink.runtime.io.network.partition.ResultPartitionManager) TestingResultPartitionManager(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateTest.TestingResultPartitionManager) InputChannelTestUtils.createLocalInputChannel(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createLocalInputChannel) InputChannelTestUtils.createSingleInputGate(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) PartitionNotFoundException(org.apache.flink.runtime.io.network.partition.PartitionNotFoundException) IOException(java.io.IOException) Test(org.junit.Test)

Example 20 with ResultSubpartitionView

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

the class LocalInputChannelTest method testConcurrentReleaseAndRetriggerPartitionRequest.

/**
 * Verifies that concurrent release via the SingleInputGate and re-triggering of a partition
 * request works smoothly.
 *
 * <ul>
 *   <li>SingleInputGate acquires its request lock and tries to release all registered channels.
 *       When releasing a channel, it needs to acquire the channel's shared request-release
 *       lock.
 *   <li>If a LocalInputChannel concurrently retriggers a partition request via a Timer Thread
 *       it acquires the channel's request-release lock and calls the retrigger callback on the
 *       SingleInputGate, which again tries to acquire the gate's request lock.
 * </ul>
 *
 * <p>For certain timings this obviously leads to a deadlock. This test reliably reproduced such
 * a timing (reported in FLINK-5228). This test is pretty much testing the buggy implementation
 * and has not much more general value. If it becomes obsolete at some point (future greatness
 * ;)), feel free to remove it.
 *
 * <p>The fix in the end was to to not acquire the channels lock when releasing it and/or not
 * doing any input gate callbacks while holding the channel's lock. I decided to do both.
 */
@Test
public void testConcurrentReleaseAndRetriggerPartitionRequest() throws Exception {
    final SingleInputGate gate = createSingleInputGate(1);
    ResultPartitionManager partitionManager = mock(ResultPartitionManager.class);
    when(partitionManager.createSubpartitionView(any(ResultPartitionID.class), anyInt(), any(BufferAvailabilityListener.class))).thenAnswer((Answer<ResultSubpartitionView>) invocationOnMock -> {
        Thread.sleep(100);
        throw new PartitionNotFoundException(new ResultPartitionID());
    });
    final LocalInputChannel channel = createLocalInputChannel(gate, partitionManager, 1, 1);
    Thread releaser = new Thread(() -> {
        try {
            gate.close();
        } catch (IOException ignored) {
        }
    });
    Thread requester = new Thread(() -> {
        try {
            channel.requestSubpartition();
        } catch (IOException ignored) {
        }
    });
    requester.start();
    releaser.start();
    releaser.join();
    requester.join();
}
Also used : ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Timer(java.util.Timer) Lists(org.apache.flink.shaded.guava30.com.google.common.collect.Lists) ResultPartition(org.apache.flink.runtime.io.network.partition.ResultPartition) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CheckpointStorageLocationReference.getDefault(org.apache.flink.runtime.state.CheckpointStorageLocationReference.getDefault) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ResultSubpartition(org.apache.flink.runtime.io.network.partition.ResultSubpartition) Assert.fail(org.junit.Assert.fail) TimerTask(java.util.TimerTask) TaskEventDispatcher(org.apache.flink.runtime.io.network.TaskEventDispatcher) CheckpointType(org.apache.flink.runtime.checkpoint.CheckpointType) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) EventSerializer(org.apache.flink.runtime.io.network.api.serialization.EventSerializer) ResultPartitionBuilder(org.apache.flink.runtime.io.network.partition.ResultPartitionBuilder) InputChannelTestUtils(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) BufferWritingResultPartition(org.apache.flink.runtime.io.network.partition.BufferWritingResultPartition) PartitionNotFoundException(org.apache.flink.runtime.io.network.partition.PartitionNotFoundException) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) Executors(java.util.concurrent.Executors) PipelinedResultPartition(org.apache.flink.runtime.io.network.partition.PipelinedResultPartition) List(java.util.List) RecordingChannelStateWriter(org.apache.flink.runtime.checkpoint.channel.RecordingChannelStateWriter) CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) Preconditions.checkArgument(org.apache.flink.util.Preconditions.checkArgument) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) ResultPartitionManager(org.apache.flink.runtime.io.network.partition.ResultPartitionManager) ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntermediateResultPartitionID(org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID) TestBufferFactory(org.apache.flink.runtime.io.network.util.TestBufferFactory) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) BufferConsumer(org.apache.flink.runtime.io.network.buffer.BufferConsumer) InputChannelTestUtils.createSingleInputGate(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate) ResultPartitionType(org.apache.flink.runtime.io.network.partition.ResultPartitionType) Callable(java.util.concurrent.Callable) CompletableFuture(java.util.concurrent.CompletableFuture) BufferProvider(org.apache.flink.runtime.io.network.buffer.BufferProvider) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) TestingResultPartitionManager(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateTest.TestingResultPartitionManager) Answer(org.mockito.stubbing.Answer) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) BufferAvailabilityListener(org.apache.flink.runtime.io.network.partition.BufferAvailabilityListener) InputChannelTestUtils.createLocalInputChannel(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createLocalInputChannel) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) InputGateFairnessTest.setupInputGate(org.apache.flink.runtime.io.network.partition.InputGateFairnessTest.setupInputGate) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CheckedSupplier(org.apache.flink.util.function.CheckedSupplier) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) TestProducerSource(org.apache.flink.runtime.io.network.util.TestProducerSource) ExecutorService(java.util.concurrent.ExecutorService) CheckpointStorageLocationReference(org.apache.flink.runtime.state.CheckpointStorageLocationReference) Assert.assertNotNull(org.junit.Assert.assertNotNull) BufferPool(org.apache.flink.runtime.io.network.buffer.BufferPool) Matchers(org.hamcrest.Matchers) Assert.assertTrue(org.junit.Assert.assertTrue) TestPartitionProducer(org.apache.flink.runtime.io.network.util.TestPartitionProducer) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) BufferBuilderTestUtils.createFilledFinishedBufferConsumer(org.apache.flink.runtime.io.network.buffer.BufferBuilderTestUtils.createFilledFinishedBufferConsumer) Mockito.verify(org.mockito.Mockito.verify) NoOpFileChannelManager(org.apache.flink.runtime.io.disk.NoOpFileChannelManager) PartitionTestUtils(org.apache.flink.runtime.io.network.partition.PartitionTestUtils) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) PartitionNotFoundException(org.apache.flink.runtime.io.network.partition.PartitionNotFoundException) ResultSubpartitionView(org.apache.flink.runtime.io.network.partition.ResultSubpartitionView) BufferAvailabilityListener(org.apache.flink.runtime.io.network.partition.BufferAvailabilityListener) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) IntermediateResultPartitionID(org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID) IOException(java.io.IOException) ResultPartitionManager(org.apache.flink.runtime.io.network.partition.ResultPartitionManager) TestingResultPartitionManager(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateTest.TestingResultPartitionManager) InputChannelTestUtils.createLocalInputChannel(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createLocalInputChannel) InputChannelTestUtils.createSingleInputGate(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate) Test(org.junit.Test)

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