Search in sources :

Example 21 with SingleInputGate

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

the class NettyShuffleUtilsTest method createInputGate.

private SingleInputGate createInputGate(NettyShuffleEnvironment network, ResultPartitionType resultPartitionType, int numInputChannels) throws IOException {
    ShuffleDescriptor[] shuffleDescriptors = new NettyShuffleDescriptor[numInputChannels];
    for (int i = 0; i < numInputChannels; i++) {
        shuffleDescriptors[i] = createRemoteWithIdAndLocation(new IntermediateResultPartitionID(), ResourceID.generate());
    }
    InputGateDeploymentDescriptor inputGateDeploymentDescriptor = new InputGateDeploymentDescriptor(new IntermediateDataSetID(), resultPartitionType, 0, shuffleDescriptors);
    ExecutionAttemptID consumerID = new ExecutionAttemptID();
    Collection<SingleInputGate> inputGates = network.createInputGates(network.createShuffleIOOwnerContext("", consumerID, new UnregisteredMetricsGroup()), SingleInputGateBuilder.NO_OP_PRODUCER_CHECKER, Collections.singletonList(inputGateDeploymentDescriptor));
    return inputGates.iterator().next();
}
Also used : UnregisteredMetricsGroup(org.apache.flink.metrics.groups.UnregisteredMetricsGroup) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) IntermediateDataSetID(org.apache.flink.runtime.jobgraph.IntermediateDataSetID) InputGateDeploymentDescriptor(org.apache.flink.runtime.deployment.InputGateDeploymentDescriptor) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) IntermediateResultPartitionID(org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID)

Example 22 with SingleInputGate

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

the class CheckpointedInputGateTest method testPriorityBeforeClose.

/**
 * Tests a priority notification happening right before cancellation. The mail would be
 * processed while draining mailbox but can't pull any data anymore.
 */
@Test
public void testPriorityBeforeClose() throws IOException, InterruptedException {
    NetworkBufferPool bufferPool = new NetworkBufferPool(10, 1024);
    try (Closer closer = Closer.create()) {
        closer.register(bufferPool::destroy);
        for (int repeat = 0; repeat < 100; repeat++) {
            setUp();
            SingleInputGate singleInputGate = new SingleInputGateBuilder().setNumberOfChannels(2).setBufferPoolFactory(bufferPool.createBufferPool(2, Integer.MAX_VALUE)).setSegmentProvider(bufferPool).setChannelFactory(InputChannelBuilder::buildRemoteChannel).build();
            singleInputGate.setup();
            ((RemoteInputChannel) singleInputGate.getChannel(0)).requestSubpartition();
            final TaskMailboxImpl mailbox = new TaskMailboxImpl();
            MailboxExecutorImpl mailboxExecutor = new MailboxExecutorImpl(mailbox, 0, StreamTaskActionExecutor.IMMEDIATE);
            ValidatingCheckpointHandler validatingHandler = new ValidatingCheckpointHandler(1);
            SingleCheckpointBarrierHandler barrierHandler = TestBarrierHandlerFactory.forTarget(validatingHandler).create(singleInputGate, new MockChannelStateWriter());
            CheckpointedInputGate checkpointedInputGate = new CheckpointedInputGate(singleInputGate, barrierHandler, mailboxExecutor, UpstreamRecoveryTracker.forInputGate(singleInputGate));
            final int oldSize = mailbox.size();
            enqueue(checkpointedInputGate, 0, barrier(1));
            // wait for priority mail to be enqueued
            Deadline deadline = Deadline.fromNow(Duration.ofMinutes(1));
            while (deadline.hasTimeLeft() && oldSize >= mailbox.size()) {
                Thread.sleep(1);
            }
            // test the race condition
            // either priority event could be handled, then we expect a checkpoint to be
            // triggered or closing came first in which case we expect a CancelTaskException
            CountDownLatch beforeLatch = new CountDownLatch(2);
            final CheckedThread canceler = new CheckedThread("Canceler") {

                @Override
                public void go() throws IOException {
                    beforeLatch.countDown();
                    singleInputGate.close();
                }
            };
            canceler.start();
            beforeLatch.countDown();
            try {
                while (mailboxExecutor.tryYield()) {
                }
                assertEquals(1L, validatingHandler.triggeredCheckpointCounter);
            } catch (CancelTaskException e) {
            }
            canceler.join();
        }
    }
}
Also used : Closer(org.apache.flink.shaded.guava30.com.google.common.io.Closer) MockChannelStateWriter(org.apache.flink.runtime.checkpoint.channel.MockChannelStateWriter) MailboxExecutorImpl(org.apache.flink.streaming.runtime.tasks.mailbox.MailboxExecutorImpl) Deadline(org.apache.flink.api.common.time.Deadline) CountDownLatch(java.util.concurrent.CountDownLatch) CheckedThread(org.apache.flink.core.testutils.CheckedThread) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) SingleInputGateBuilder(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder) TaskMailboxImpl(org.apache.flink.streaming.runtime.tasks.mailbox.TaskMailboxImpl) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) Test(org.junit.Test)

Example 23 with SingleInputGate

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

the class UnalignedCheckpointsTest method testEndOfStreamWithPendingCheckpoint.

@Test
public void testEndOfStreamWithPendingCheckpoint() throws Exception {
    final int numberOfChannels = 2;
    final ValidatingCheckpointInvokable invokable = new ValidatingCheckpointInvokable();
    final SingleInputGate inputGate = new SingleInputGateBuilder().setChannelFactory(InputChannelBuilder::buildLocalChannel).setNumberOfChannels(numberOfChannels).build();
    final SingleCheckpointBarrierHandler handler = SingleCheckpointBarrierHandler.createUnalignedCheckpointBarrierHandler(TestSubtaskCheckpointCoordinator.INSTANCE, "test", invokable, SystemClock.getInstance(), false, inputGate);
    // should trigger respective checkpoint
    handler.processBarrier(buildCheckpointBarrier(DEFAULT_CHECKPOINT_ID), new InputChannelInfo(0, 0), false);
    assertTrue(handler.isCheckpointPending());
    assertEquals(DEFAULT_CHECKPOINT_ID, handler.getLatestCheckpointId());
    assertEquals(numberOfChannels, handler.getNumOpenChannels());
    // should abort current checkpoint while processing eof
    handler.processEndOfPartition(new InputChannelInfo(0, 0));
    assertFalse(handler.isCheckpointPending());
    assertEquals(DEFAULT_CHECKPOINT_ID, handler.getLatestCheckpointId());
    assertEquals(numberOfChannels - 1, handler.getNumOpenChannels());
    assertEquals(DEFAULT_CHECKPOINT_ID, invokable.getAbortedCheckpointId());
}
Also used : SingleInputGateBuilder(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder) InputChannelBuilder(org.apache.flink.runtime.io.network.partition.consumer.InputChannelBuilder) InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) Test(org.junit.Test)

Example 24 with SingleInputGate

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

the class UnalignedCheckpointsTest method createInputGate.

private CheckpointedInputGate createInputGate(int numberOfChannels, AbstractInvokable toNotify, boolean enableCheckpointsAfterTasksFinished) throws IOException {
    final NettyShuffleEnvironment environment = new NettyShuffleEnvironmentBuilder().build();
    SingleInputGate gate = new SingleInputGateBuilder().setNumberOfChannels(numberOfChannels).setupBufferPoolFactory(environment).build();
    gate.setInputChannels(IntStream.range(0, numberOfChannels).mapToObj(channelIndex -> InputChannelBuilder.newBuilder().setChannelIndex(channelIndex).setStateWriter(channelStateWriter).setupFromNettyShuffleEnvironment(environment).setConnectionManager(new TestingConnectionManager()).buildRemoteChannel(gate)).toArray(RemoteInputChannel[]::new));
    sequenceNumbers = new int[numberOfChannels];
    gate.setup();
    gate.requestPartitions();
    return createCheckpointedInputGate(gate, toNotify, enableCheckpointsAfterTasksFinished);
}
Also used : SingleInputGateBuilder(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder) TestingConnectionManager(org.apache.flink.runtime.io.network.TestingConnectionManager) NettyShuffleEnvironmentBuilder(org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder) NettyShuffleEnvironment(org.apache.flink.runtime.io.network.NettyShuffleEnvironment) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel)

Example 25 with SingleInputGate

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

the class CheckpointedInputGateTest method setupInputGateWithAlternatingController.

private CheckpointedInputGate setupInputGateWithAlternatingController(int numberOfChannels, NetworkBufferPool networkBufferPool, AbstractInvokable abstractInvokable, RecordingChannelStateWriter stateWriter) throws Exception {
    ConnectionManager connectionManager = new TestingConnectionManager();
    SingleInputGate singleInputGate = new SingleInputGateBuilder().setBufferPoolFactory(networkBufferPool.createBufferPool(numberOfChannels, Integer.MAX_VALUE)).setSegmentProvider(networkBufferPool).setChannelFactory((builder, gate) -> builder.setConnectionManager(connectionManager).buildRemoteChannel(gate)).setNumberOfChannels(numberOfChannels).setChannelStateWriter(stateWriter).build();
    singleInputGate.setup();
    MailboxExecutorImpl mailboxExecutor = new MailboxExecutorImpl(new TaskMailboxImpl(), 0, StreamTaskActionExecutor.IMMEDIATE);
    SingleCheckpointBarrierHandler barrierHandler = TestBarrierHandlerFactory.forTarget(abstractInvokable).create(singleInputGate, stateWriter);
    CheckpointedInputGate checkpointedInputGate = new CheckpointedInputGate(singleInputGate, barrierHandler, mailboxExecutor, UpstreamRecoveryTracker.forInputGate(singleInputGate));
    for (int i = 0; i < numberOfChannels; i++) {
        ((RemoteInputChannel) checkpointedInputGate.getChannel(i)).requestSubpartition();
    }
    return checkpointedInputGate;
}
Also used : Deadline(org.apache.flink.api.common.time.Deadline) TestingConnectionManager(org.apache.flink.runtime.io.network.TestingConnectionManager) SystemClock(org.apache.flink.util.clock.SystemClock) EndOfPartitionEvent(org.apache.flink.runtime.io.network.api.EndOfPartitionEvent) HashMap(java.util.HashMap) PartitionRequestClient(org.apache.flink.runtime.io.network.PartitionRequestClient) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) CheckedThread(org.apache.flink.core.testutils.CheckedThread) Duration(java.time.Duration) TaskMailboxImpl(org.apache.flink.streaming.runtime.tasks.mailbox.TaskMailboxImpl) BufferBuilderTestUtils.buildSomeBuffer(org.apache.flink.runtime.io.network.buffer.BufferBuilderTestUtils.buildSomeBuffer) InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) MockChannelStateWriter(org.apache.flink.runtime.checkpoint.channel.MockChannelStateWriter) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) Before(org.junit.Before) CheckpointStorageLocationReference(org.apache.flink.runtime.state.CheckpointStorageLocationReference) EndOfChannelStateEvent(org.apache.flink.runtime.io.network.partition.consumer.EndOfChannelStateEvent) CheckpointType(org.apache.flink.runtime.checkpoint.CheckpointType) SingleInputGateBuilder(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) EventSerializer(org.apache.flink.runtime.io.network.api.serialization.EventSerializer) AbstractEvent(org.apache.flink.runtime.event.AbstractEvent) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) ConnectionManager(org.apache.flink.runtime.io.network.ConnectionManager) Closer(org.apache.flink.shaded.guava30.com.google.common.io.Closer) InputChannelBuilder(org.apache.flink.runtime.io.network.partition.consumer.InputChannelBuilder) AbstractInvokable(org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable) Assert.assertTrue(org.junit.Assert.assertTrue) ConnectionID(org.apache.flink.runtime.io.network.ConnectionID) Test(org.junit.Test) IOException(java.io.IOException) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) MailboxExecutorImpl(org.apache.flink.streaming.runtime.tasks.mailbox.MailboxExecutorImpl) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) CountDownLatch(java.util.concurrent.CountDownLatch) RecordingChannelStateWriter(org.apache.flink.runtime.checkpoint.channel.RecordingChannelStateWriter) CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) TestingPartitionRequestClient(org.apache.flink.runtime.io.network.TestingPartitionRequestClient) DummyEnvironment(org.apache.flink.runtime.operators.testutils.DummyEnvironment) BufferOrEvent(org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent) Assert.assertEquals(org.junit.Assert.assertEquals) StreamTaskActionExecutor(org.apache.flink.streaming.runtime.tasks.StreamTaskActionExecutor) SingleInputGateBuilder(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder) MailboxExecutorImpl(org.apache.flink.streaming.runtime.tasks.mailbox.MailboxExecutorImpl) TestingConnectionManager(org.apache.flink.runtime.io.network.TestingConnectionManager) ConnectionManager(org.apache.flink.runtime.io.network.ConnectionManager) TaskMailboxImpl(org.apache.flink.streaming.runtime.tasks.mailbox.TaskMailboxImpl) TestingConnectionManager(org.apache.flink.runtime.io.network.TestingConnectionManager) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel)

Aggregations

SingleInputGate (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate)56 Test (org.junit.Test)32 RemoteInputChannel (org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel)30 SingleInputGateBuilder (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder)22 NetworkBufferPool (org.apache.flink.runtime.io.network.buffer.NetworkBufferPool)21 InputChannelTestUtils.createRemoteInputChannel (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createRemoteInputChannel)15 InputChannelTestUtils.createSingleInputGate (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createSingleInputGate)15 BufferPool (org.apache.flink.runtime.io.network.buffer.BufferPool)14 IntermediateDataSetID (org.apache.flink.runtime.jobgraph.IntermediateDataSetID)11 EmbeddedChannel (org.apache.flink.shaded.netty4.io.netty.channel.embedded.EmbeddedChannel)10 InputChannelInfo (org.apache.flink.runtime.checkpoint.channel.InputChannelInfo)8 IOException (java.io.IOException)7 ConnectionManager (org.apache.flink.runtime.io.network.ConnectionManager)7 PartitionRequestClient (org.apache.flink.runtime.io.network.PartitionRequestClient)7 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)7 BufferResponse (org.apache.flink.runtime.io.network.netty.NettyMessage.BufferResponse)7 InputChannelTestUtils.createDummyConnectionManager (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createDummyConnectionManager)7 InputChannelBuilder (org.apache.flink.runtime.io.network.partition.consumer.InputChannelBuilder)7 TestInputChannel (org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel)6 CheckpointOptions (org.apache.flink.runtime.checkpoint.CheckpointOptions)5