Search in sources :

Example 16 with InputChannelInfo

use of org.apache.flink.runtime.checkpoint.channel.InputChannelInfo in project flink by apache.

the class AlternatingCheckpointsTest method testOutOfOrderBarrier.

@Test
public void testOutOfOrderBarrier() throws Exception {
    SingleInputGate inputGate = new SingleInputGateBuilder().setNumberOfChannels(2).build();
    TestInputChannel firstChannel = new TestInputChannel(inputGate, 0);
    TestInputChannel secondChannel = new TestInputChannel(inputGate, 1);
    inputGate.setInputChannels(firstChannel, secondChannel);
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    SingleCheckpointBarrierHandler barrierHandler = getTestBarrierHandlerFactory(target).create(inputGate);
    long checkpointId = 10;
    long outOfOrderSavepointId = 5;
    barrierHandler.processBarrier(new CheckpointBarrier(checkpointId, clock.relativeTimeMillis(), new CheckpointOptions(CHECKPOINT, getDefault())), new InputChannelInfo(0, 0), false);
    secondChannel.setBlocked(true);
    barrierHandler.processBarrier(new CheckpointBarrier(outOfOrderSavepointId, clock.relativeTimeMillis(), new CheckpointOptions(SavepointType.savepoint(SavepointFormatType.CANONICAL), getDefault())), new InputChannelInfo(0, 1), false);
    assertEquals(checkpointId, barrierHandler.getLatestCheckpointId());
    assertFalse(secondChannel.isBlocked());
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) SingleInputGateBuilder(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder) InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) TestInputChannel(org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate) Test(org.junit.Test)

Example 17 with InputChannelInfo

use of org.apache.flink.runtime.checkpoint.channel.InputChannelInfo in project flink by apache.

the class InputProcessorUtilTest method testCreateCheckpointedMultipleInputGate.

@Test
public void testCreateCheckpointedMultipleInputGate() throws Exception {
    try (CloseableRegistry registry = new CloseableRegistry()) {
        MockEnvironment environment = new MockEnvironmentBuilder().build();
        MockStreamTask streamTask = new MockStreamTaskBuilder(environment).build();
        StreamConfig streamConfig = new StreamConfig(environment.getJobConfiguration());
        streamConfig.setCheckpointMode(CheckpointingMode.EXACTLY_ONCE);
        streamConfig.setUnalignedCheckpointsEnabled(true);
        // First input gate has index larger than the second
        List<IndexedInputGate>[] inputGates = new List[] { Collections.singletonList(getGate(1, 4)), Collections.singletonList(getGate(0, 2)) };
        CheckpointBarrierHandler barrierHandler = InputProcessorUtil.createCheckpointBarrierHandler(streamTask, streamConfig, new TestSubtaskCheckpointCoordinator(new MockChannelStateWriter()), streamTask.getName(), inputGates, Collections.emptyList(), new SyncMailboxExecutor(), new TestProcessingTimeService());
        CheckpointedInputGate[] checkpointedMultipleInputGate = InputProcessorUtil.createCheckpointedMultipleInputGate(new SyncMailboxExecutor(), inputGates, environment.getMetricGroup().getIOMetricGroup(), barrierHandler, streamConfig);
        for (CheckpointedInputGate checkpointedInputGate : checkpointedMultipleInputGate) {
            registry.registerCloseable(checkpointedInputGate);
        }
        List<IndexedInputGate> allInputGates = Arrays.stream(inputGates).flatMap(gates -> gates.stream()).collect(Collectors.toList());
        for (IndexedInputGate inputGate : allInputGates) {
            for (int channelId = 0; channelId < inputGate.getNumberOfInputChannels(); channelId++) {
                barrierHandler.processBarrier(new CheckpointBarrier(1, 42, CheckpointOptions.unaligned(CheckpointType.CHECKPOINT, CheckpointStorageLocationReference.getDefault())), new InputChannelInfo(inputGate.getGateIndex(), channelId), false);
            }
        }
        assertTrue(barrierHandler.getAllBarriersReceivedFuture(1).isDone());
    }
}
Also used : MockStreamTaskBuilder(org.apache.flink.streaming.util.MockStreamTaskBuilder) MockChannelStateWriter(org.apache.flink.runtime.checkpoint.channel.MockChannelStateWriter) Arrays(java.util.Arrays) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) CheckpointingMode(org.apache.flink.streaming.api.CheckpointingMode) CloseableRegistry(org.apache.flink.core.fs.CloseableRegistry) TestSubtaskCheckpointCoordinator(org.apache.flink.streaming.runtime.tasks.TestSubtaskCheckpointCoordinator) MockStreamTask(org.apache.flink.streaming.util.MockStreamTask) MockEnvironment(org.apache.flink.runtime.operators.testutils.MockEnvironment) 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) SyncMailboxExecutor(org.apache.flink.runtime.mailbox.SyncMailboxExecutor) CheckpointStorageLocationReference(org.apache.flink.runtime.state.CheckpointStorageLocationReference) CheckpointType(org.apache.flink.runtime.checkpoint.CheckpointType) SingleInputGateBuilder(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder) InputChannelBuilder(org.apache.flink.runtime.io.network.partition.consumer.InputChannelBuilder) MockStreamTaskBuilder(org.apache.flink.streaming.util.MockStreamTaskBuilder) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) MockEnvironmentBuilder(org.apache.flink.runtime.operators.testutils.MockEnvironmentBuilder) TestProcessingTimeService(org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService) Collectors(java.util.stream.Collectors) List(java.util.List) CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) IndexedInputGate(org.apache.flink.runtime.io.network.partition.consumer.IndexedInputGate) Collections(java.util.Collections) MockEnvironmentBuilder(org.apache.flink.runtime.operators.testutils.MockEnvironmentBuilder) InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) SyncMailboxExecutor(org.apache.flink.runtime.mailbox.SyncMailboxExecutor) MockStreamTask(org.apache.flink.streaming.util.MockStreamTask) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) IndexedInputGate(org.apache.flink.runtime.io.network.partition.consumer.IndexedInputGate) CloseableRegistry(org.apache.flink.core.fs.CloseableRegistry) TestSubtaskCheckpointCoordinator(org.apache.flink.streaming.runtime.tasks.TestSubtaskCheckpointCoordinator) CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) MockEnvironment(org.apache.flink.runtime.operators.testutils.MockEnvironment) TestProcessingTimeService(org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService) List(java.util.List) Test(org.junit.Test)

Example 18 with InputChannelInfo

use of org.apache.flink.runtime.checkpoint.channel.InputChannelInfo in project flink by apache.

the class StreamTask method triggerUnfinishedChannelsCheckpoint.

private boolean triggerUnfinishedChannelsCheckpoint(CheckpointMetaData checkpointMetaData, CheckpointOptions checkpointOptions) throws Exception {
    Optional<CheckpointBarrierHandler> checkpointBarrierHandler = getCheckpointBarrierHandler();
    checkState(checkpointBarrierHandler.isPresent(), "CheckpointBarrier should exist for tasks with network inputs.");
    CheckpointBarrier barrier = new CheckpointBarrier(checkpointMetaData.getCheckpointId(), checkpointMetaData.getTimestamp(), checkpointOptions);
    for (IndexedInputGate inputGate : getEnvironment().getAllInputGates()) {
        if (!inputGate.isFinished()) {
            for (InputChannelInfo channelInfo : inputGate.getUnfinishedChannels()) {
                checkpointBarrierHandler.get().processBarrier(barrier, channelInfo, true);
            }
        }
    }
    return true;
}
Also used : CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) CheckpointBarrierHandler(org.apache.flink.streaming.runtime.io.checkpointing.CheckpointBarrierHandler) IndexedInputGate(org.apache.flink.runtime.io.network.partition.consumer.IndexedInputGate)

Example 19 with InputChannelInfo

use of org.apache.flink.runtime.checkpoint.channel.InputChannelInfo in project flink by apache.

the class StreamTaskNetworkInputTest method testReleasingDeserializerTimely.

@Test
public void testReleasingDeserializerTimely() throws Exception {
    int numInputChannels = 2;
    LongSerializer inSerializer = LongSerializer.INSTANCE;
    StreamTestSingleInputGate<Long> inputGate = new StreamTestSingleInputGate<>(numInputChannels, 0, inSerializer, 1024);
    DataOutput<Long> output = new NoOpDataOutput<>();
    Map<InputChannelInfo, TestRecordDeserializer> deserializers = createDeserializers(inputGate.getInputGate());
    Map<InputChannelInfo, TestRecordDeserializer> copiedDeserializers = new HashMap<>(deserializers);
    StreamTaskInput<Long> input = new TestStreamTaskNetworkInput(inputGate, inSerializer, numInputChannels, deserializers);
    for (InputChannelInfo channelInfo : inputGate.getInputGate().getChannelInfos()) {
        assertNotNull(deserializers.get(channelInfo));
        inputGate.sendEvent(EndOfPartitionEvent.INSTANCE, channelInfo.getInputChannelIdx());
        input.emitNext(output);
        assertTrue(copiedDeserializers.get(channelInfo).isCleared());
        assertNull(deserializers.get(channelInfo));
    }
}
Also used : LongSerializer(org.apache.flink.api.common.typeutils.base.LongSerializer) InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) HashMap(java.util.HashMap) StreamTestSingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.StreamTestSingleInputGate) Test(org.junit.Test)

Example 20 with InputChannelInfo

use of org.apache.flink.runtime.checkpoint.channel.InputChannelInfo in project flink by apache.

the class SingleInputGateTest method testSingleInputGateInfo.

@Test
public void testSingleInputGateInfo() {
    final int numSingleInputGates = 2;
    final int numInputChannels = 3;
    for (int i = 0; i < numSingleInputGates; i++) {
        final SingleInputGate gate = new SingleInputGateBuilder().setSingleInputGateIndex(i).setNumberOfChannels(numInputChannels).build();
        int channelCounter = 0;
        for (InputChannel inputChannel : gate.getInputChannels().values()) {
            InputChannelInfo channelInfo = inputChannel.getChannelInfo();
            assertEquals(i, channelInfo.getGateIdx());
            assertEquals(channelCounter++, channelInfo.getInputChannelIdx());
        }
    }
}
Also used : InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) InputChannelTestUtils.createRemoteInputChannel(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createRemoteInputChannel) InputChannelTestUtils.createLocalInputChannel(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createLocalInputChannel) Test(org.junit.Test)

Aggregations

InputChannelInfo (org.apache.flink.runtime.checkpoint.channel.InputChannelInfo)30 Test (org.junit.Test)21 SingleInputGate (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate)9 CheckpointBarrier (org.apache.flink.runtime.io.network.api.CheckpointBarrier)8 SingleInputGateBuilder (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder)8 CheckpointOptions (org.apache.flink.runtime.checkpoint.CheckpointOptions)5 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)5 BufferBuilder (org.apache.flink.runtime.io.network.buffer.BufferBuilder)4 MemorySegment (org.apache.flink.core.memory.MemorySegment)3 ResultSubpartitionInfo (org.apache.flink.runtime.checkpoint.channel.ResultSubpartitionInfo)3 CancelCheckpointMarker (org.apache.flink.runtime.io.network.api.CancelCheckpointMarker)3 SubtaskConnectionDescriptor (org.apache.flink.runtime.io.network.api.SubtaskConnectionDescriptor)3 BufferBuilderTestUtils.createBufferBuilder (org.apache.flink.runtime.io.network.buffer.BufferBuilderTestUtils.createBufferBuilder)3 BufferOrEvent (org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent)3 TestInputChannel (org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 LongSerializer (org.apache.flink.api.common.typeutils.base.LongSerializer)2 RecordingChannelStateWriter (org.apache.flink.runtime.checkpoint.channel.RecordingChannelStateWriter)2 NetworkBuffer (org.apache.flink.runtime.io.network.buffer.NetworkBuffer)2