Search in sources :

Example 1 with SyncMailboxExecutor

use of org.apache.flink.runtime.mailbox.SyncMailboxExecutor 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 2 with SyncMailboxExecutor

use of org.apache.flink.runtime.mailbox.SyncMailboxExecutor in project flink by apache.

the class StreamTaskNetworkInputTest method testSnapshotAfterEndOfPartition.

@Test
public void testSnapshotAfterEndOfPartition() throws Exception {
    int numInputChannels = 1;
    int channelId = 0;
    int checkpointId = 0;
    VerifyRecordsDataOutput<Long> output = new VerifyRecordsDataOutput<>();
    LongSerializer inSerializer = LongSerializer.INSTANCE;
    StreamTestSingleInputGate<Long> inputGate = new StreamTestSingleInputGate<>(numInputChannels, 0, inSerializer, 1024);
    StreamTaskInput<Long> input = new StreamTaskNetworkInput<>(new CheckpointedInputGate(inputGate.getInputGate(), SingleCheckpointBarrierHandler.createUnalignedCheckpointBarrierHandler(TestSubtaskCheckpointCoordinator.INSTANCE, "test", new DummyCheckpointInvokable(), SystemClock.getInstance(), false, inputGate.getInputGate()), new SyncMailboxExecutor()), inSerializer, ioManager, new StatusWatermarkValve(numInputChannels), 0);
    inputGate.sendEvent(new CheckpointBarrier(checkpointId, 0L, CheckpointOptions.forCheckpointWithDefaultLocation().toUnaligned()), channelId);
    inputGate.sendElement(new StreamRecord<>(42L), channelId);
    assertHasNextElement(input, output);
    assertHasNextElement(input, output);
    assertEquals(1, output.getNumberOfEmittedRecords());
    // send EndOfPartitionEvent and ensure that deserializer has been released
    inputGate.sendEvent(EndOfPartitionEvent.INSTANCE, channelId);
    input.emitNext(output);
    // now snapshot all inflight buffers
    CompletableFuture<Void> completableFuture = input.prepareSnapshot(ChannelStateWriter.NO_OP, checkpointId);
    completableFuture.join();
}
Also used : LongSerializer(org.apache.flink.api.common.typeutils.base.LongSerializer) SyncMailboxExecutor(org.apache.flink.runtime.mailbox.SyncMailboxExecutor) StreamTestSingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.StreamTestSingleInputGate) StatusWatermarkValve(org.apache.flink.streaming.runtime.watermarkstatus.StatusWatermarkValve) CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) DummyCheckpointInvokable(org.apache.flink.runtime.operators.testutils.DummyCheckpointInvokable) CheckpointedInputGate(org.apache.flink.streaming.runtime.io.checkpointing.CheckpointedInputGate) Test(org.junit.Test)

Example 3 with SyncMailboxExecutor

use of org.apache.flink.runtime.mailbox.SyncMailboxExecutor in project flink by apache.

the class AlignedCheckpointsMassiveRandomTest method testWithTwoChannelsAndRandomBarriers.

@Test
public void testWithTwoChannelsAndRandomBarriers() throws Exception {
    NetworkBufferPool networkBufferPool1 = null;
    NetworkBufferPool networkBufferPool2 = null;
    try {
        networkBufferPool1 = new NetworkBufferPool(100, PAGE_SIZE);
        networkBufferPool2 = new NetworkBufferPool(100, PAGE_SIZE);
        BufferPool pool1 = networkBufferPool1.createBufferPool(100, 100);
        BufferPool pool2 = networkBufferPool2.createBufferPool(100, 100);
        RandomGeneratingInputGate myIG = new RandomGeneratingInputGate(new BufferPool[] { pool1, pool2 }, new BarrierGenerator[] { new CountBarrier(100000), new RandomBarrier(100000) });
        CheckpointedInputGate checkpointedInputGate = new CheckpointedInputGate(myIG, SingleCheckpointBarrierHandler.aligned("Testing: No task associated", new DummyCheckpointInvokable(), SystemClock.getInstance(), myIG.getNumberOfInputChannels(), (callable, duration) -> () -> {
        }, true, myIG), new SyncMailboxExecutor());
        for (int i = 0; i < 2000000; i++) {
            BufferOrEvent boe = checkpointedInputGate.pollNext().get();
            if (boe.isBuffer()) {
                boe.getBuffer().recycleBuffer();
            }
        }
    } finally {
        if (networkBufferPool1 != null) {
            networkBufferPool1.destroyAllBufferPools();
            networkBufferPool1.destroy();
        }
        if (networkBufferPool2 != null) {
            networkBufferPool2.destroyAllBufferPools();
            networkBufferPool2.destroy();
        }
    }
}
Also used : SyncMailboxExecutor(org.apache.flink.runtime.mailbox.SyncMailboxExecutor) IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) SystemClock(org.apache.flink.util.clock.SystemClock) DummyCheckpointInvokable(org.apache.flink.runtime.operators.testutils.DummyCheckpointInvokable) BufferPool(org.apache.flink.runtime.io.network.buffer.BufferPool) Test(org.junit.Test) IOException(java.io.IOException) Random(java.util.Random) CompletableFuture(java.util.concurrent.CompletableFuture) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) Collectors(java.util.stream.Collectors) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) List(java.util.List) CheckpointBarrier(org.apache.flink.runtime.io.network.api.CheckpointBarrier) InputChannel(org.apache.flink.runtime.io.network.partition.consumer.InputChannel) TaskEvent(org.apache.flink.runtime.event.TaskEvent) Optional(java.util.Optional) IndexedInputGate(org.apache.flink.runtime.io.network.partition.consumer.IndexedInputGate) Collections(java.util.Collections) InputChannelInfo(org.apache.flink.runtime.checkpoint.channel.InputChannelInfo) BufferOrEvent(org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent) BufferPool(org.apache.flink.runtime.io.network.buffer.BufferPool) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) DummyCheckpointInvokable(org.apache.flink.runtime.operators.testutils.DummyCheckpointInvokable) SyncMailboxExecutor(org.apache.flink.runtime.mailbox.SyncMailboxExecutor) NetworkBufferPool(org.apache.flink.runtime.io.network.buffer.NetworkBufferPool) BufferOrEvent(org.apache.flink.runtime.io.network.partition.consumer.BufferOrEvent) Test(org.junit.Test)

Example 4 with SyncMailboxExecutor

use of org.apache.flink.runtime.mailbox.SyncMailboxExecutor in project flink by apache.

the class AlternatingCheckpointsTest method testBarrierHandling.

private void testBarrierHandling(SnapshotType checkpointType) throws Exception {
    final long barrierId = 123L;
    ValidatingCheckpointHandler target = new ValidatingCheckpointHandler();
    SingleInputGate gate = new SingleInputGateBuilder().setNumberOfChannels(2).build();
    TestInputChannel fast = new TestInputChannel(gate, 0, false, true);
    TestInputChannel slow = new TestInputChannel(gate, 1, false, true);
    gate.setInputChannels(fast, slow);
    SingleCheckpointBarrierHandler barrierHandler = getTestBarrierHandlerFactory(target).create(gate);
    CheckpointedInputGate checkpointedGate = new CheckpointedInputGate(gate, barrierHandler, new SyncMailboxExecutor());
    if (checkpointType.isSavepoint()) {
        fast.setBlocked(true);
        slow.setBlocked(true);
    }
    CheckpointOptions options = checkpointType.isSavepoint() ? alignedNoTimeout(checkpointType, getDefault()) : unaligned(CheckpointType.CHECKPOINT, getDefault());
    Buffer barrier = barrier(barrierId, 1, options);
    send(barrier.retainBuffer(), fast, checkpointedGate);
    assertEquals(checkpointType.isSavepoint(), target.triggeredCheckpoints.isEmpty());
    send(barrier.retainBuffer(), slow, checkpointedGate);
    assertEquals(singletonList(barrierId), target.triggeredCheckpoints);
    if (checkpointType.isSavepoint()) {
        for (InputChannel channel : gate.getInputChannels().values()) {
            assertFalse(String.format("channel %d should be resumed", channel.getChannelIndex()), ((TestInputChannel) channel).isBlocked());
        }
    }
}
Also used : TestBufferFactory.createBuffer(org.apache.flink.runtime.io.network.util.TestBufferFactory.createBuffer) Buffer(org.apache.flink.runtime.io.network.buffer.Buffer) EventSerializer.toBuffer(org.apache.flink.runtime.io.network.api.serialization.EventSerializer.toBuffer) SingleInputGateBuilder(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder) TestInputChannel(org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel) SyncMailboxExecutor(org.apache.flink.runtime.mailbox.SyncMailboxExecutor) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) InputChannel(org.apache.flink.runtime.io.network.partition.consumer.InputChannel) TestInputChannel(org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel) RemoteInputChannel(org.apache.flink.runtime.io.network.partition.consumer.RemoteInputChannel) SingleInputGate(org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate)

Aggregations

SyncMailboxExecutor (org.apache.flink.runtime.mailbox.SyncMailboxExecutor)4 CheckpointOptions (org.apache.flink.runtime.checkpoint.CheckpointOptions)3 CheckpointBarrier (org.apache.flink.runtime.io.network.api.CheckpointBarrier)3 Test (org.junit.Test)3 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 InputChannelInfo (org.apache.flink.runtime.checkpoint.channel.InputChannelInfo)2 Buffer (org.apache.flink.runtime.io.network.buffer.Buffer)2 IndexedInputGate (org.apache.flink.runtime.io.network.partition.consumer.IndexedInputGate)2 InputChannel (org.apache.flink.runtime.io.network.partition.consumer.InputChannel)2 SingleInputGate (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate)2 SingleInputGateBuilder (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGateBuilder)2 DummyCheckpointInvokable (org.apache.flink.runtime.operators.testutils.DummyCheckpointInvokable)2 IOException (java.io.IOException)1 Optional (java.util.Optional)1 Random (java.util.Random)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 IntStream (java.util.stream.IntStream)1