Search in sources :

Example 31 with NettyShuffleEnvironment

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

the class SourceStreamTaskTest method testTriggeringCheckpointAfterSourceThreadFinished.

@Test
public void testTriggeringCheckpointAfterSourceThreadFinished() throws Exception {
    ResultPartition[] partitionWriters = new ResultPartition[2];
    try (NettyShuffleEnvironment env = new NettyShuffleEnvironmentBuilder().setNumNetworkBuffers(partitionWriters.length * 2).build()) {
        for (int i = 0; i < partitionWriters.length; ++i) {
            partitionWriters[i] = PartitionTestUtils.createPartition(env, ResultPartitionType.PIPELINED_BOUNDED, 1);
            partitionWriters[i].setup();
        }
        final CompletableFuture<Long> checkpointCompleted = new CompletableFuture<>();
        try (StreamTaskMailboxTestHarness<String> testHarness = new StreamTaskMailboxTestHarnessBuilder<>(SourceStreamTask::new, BasicTypeInfo.STRING_TYPE_INFO).modifyStreamConfig(config -> config.setCheckpointingEnabled(true)).setCheckpointResponder(new TestCheckpointResponder() {

            @Override
            public void acknowledgeCheckpoint(JobID jobID, ExecutionAttemptID executionAttemptID, long checkpointId, CheckpointMetrics checkpointMetrics, TaskStateSnapshot subtaskState) {
                super.acknowledgeCheckpoint(jobID, executionAttemptID, checkpointId, checkpointMetrics, subtaskState);
                checkpointCompleted.complete(checkpointId);
            }
        }).addAdditionalOutput(partitionWriters).setupOperatorChain(new StreamSource<>(new MockSource(0, 0, 1))).finishForSingletonOperatorChain(StringSerializer.INSTANCE).build()) {
            testHarness.processAll();
            CompletableFuture<Void> taskFinished = testHarness.getStreamTask().getCompletionFuture();
            do {
                testHarness.processAll();
            } while (!taskFinished.isDone());
            Future<Boolean> checkpointFuture = triggerCheckpoint(testHarness, 2);
            // Notifies the result partition that all records are processed after the
            // last checkpoint is triggered.
            checkState(checkpointFuture instanceof CompletableFuture, "The trigger future should " + " be also CompletableFuture.");
            ((CompletableFuture<?>) checkpointFuture).thenAccept((ignored) -> {
                for (ResultPartition resultPartition : partitionWriters) {
                    resultPartition.onSubpartitionAllDataProcessed(0);
                }
            });
            checkpointCompleted.whenComplete((id, error) -> testHarness.getStreamTask().notifyCheckpointCompleteAsync(2));
            testHarness.finishProcessing();
            assertTrue(checkpointFuture.isDone());
            // EndOfUserRecordEvent.
            for (ResultPartition resultPartition : partitionWriters) {
                assertEquals(3, resultPartition.getNumberOfQueuedBuffers());
            }
        }
    } finally {
        for (ResultPartitionWriter writer : partitionWriters) {
            if (writer != null) {
                writer.close();
            }
        }
    }
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) MultiShotLatch(org.apache.flink.core.testutils.MultiShotLatch) EndOfData(org.apache.flink.runtime.io.network.api.EndOfData) TestCheckpointResponder(org.apache.flink.runtime.taskmanager.TestCheckpointResponder) Tuple2(org.apache.flink.api.java.tuple.Tuple2) TupleTypeInfo(org.apache.flink.api.java.typeutils.TupleTypeInfo) SavepointType(org.apache.flink.runtime.checkpoint.SavepointType) ExceptionUtils(org.apache.flink.util.ExceptionUtils) Random(java.util.Random) StringSerializer(org.apache.flink.api.common.typeutils.base.StringSerializer) StreamTaskFinalCheckpointsTest.triggerCheckpoint(org.apache.flink.streaming.runtime.tasks.StreamTaskFinalCheckpointsTest.triggerCheckpoint) StreamElementSerializer(org.apache.flink.streaming.runtime.streamrecord.StreamElementSerializer) BasicTypeInfo(org.apache.flink.api.common.typeinfo.BasicTypeInfo) ResultPartition(org.apache.flink.runtime.io.network.partition.ResultPartition) IntSerializer(org.apache.flink.api.common.typeutils.base.IntSerializer) LifeCyclePhase(org.apache.flink.streaming.runtime.tasks.LifeCycleMonitor.LifeCyclePhase) Future(java.util.concurrent.Future) RichSourceFunction(org.apache.flink.streaming.api.functions.source.RichSourceFunction) TaskStateSnapshot(org.apache.flink.runtime.checkpoint.TaskStateSnapshot) FromElementsFunction(org.apache.flink.streaming.api.functions.source.FromElementsFunction) TypeSerializer(org.apache.flink.api.common.typeutils.TypeSerializer) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) StreamElement(org.apache.flink.streaming.runtime.streamrecord.StreamElement) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) NettyShuffleEnvironment(org.apache.flink.runtime.io.network.NettyShuffleEnvironment) Executors(java.util.concurrent.Executors) BoundedOneInput(org.apache.flink.streaming.api.operators.BoundedOneInput) SimpleOperatorFactory(org.apache.flink.streaming.api.operators.SimpleOperatorFactory) Serializable(java.io.Serializable) StopMode(org.apache.flink.runtime.io.network.api.StopMode) List(java.util.List) Matchers.contains(org.hamcrest.Matchers.contains) Assert.assertFalse(org.junit.Assert.assertFalse) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) CheckpointResponder(org.apache.flink.runtime.taskmanager.CheckpointResponder) CheckpointMetrics(org.apache.flink.runtime.checkpoint.CheckpointMetrics) RecordOrEventCollectingResultPartitionWriter(org.apache.flink.runtime.io.network.api.writer.RecordOrEventCollectingResultPartitionWriter) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) INT_TYPE_INFO(org.apache.flink.api.common.typeinfo.BasicTypeInfo.INT_TYPE_INFO) CheckpointMetaData(org.apache.flink.runtime.checkpoint.CheckpointMetaData) Watermark(org.apache.flink.streaming.api.watermark.Watermark) ResultPartitionWriter(org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter) ResultPartitionType(org.apache.flink.runtime.io.network.partition.ResultPartitionType) Callable(java.util.concurrent.Callable) CompletableFuture(java.util.concurrent.CompletableFuture) STRING_TYPE_INFO(org.apache.flink.api.common.typeinfo.BasicTypeInfo.STRING_TYPE_INFO) ArrayList(java.util.ArrayList) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) SourceFunction(org.apache.flink.streaming.api.functions.source.SourceFunction) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) RichParallelSourceFunction(org.apache.flink.streaming.api.functions.source.RichParallelSourceFunction) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestHarnessUtil(org.apache.flink.streaming.util.TestHarnessUtil) CheckedSupplier(org.apache.flink.util.function.CheckedSupplier) ExecutorService(java.util.concurrent.ExecutorService) CheckpointStorageLocationReference(org.apache.flink.runtime.state.CheckpointStorageLocationReference) Preconditions.checkState(org.apache.flink.util.Preconditions.checkState) TimeCharacteristic(org.apache.flink.streaming.api.TimeCharacteristic) NettyShuffleEnvironmentBuilder(org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) Semaphore(java.util.concurrent.Semaphore) Configuration(org.apache.flink.configuration.Configuration) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) AtomicLong(java.util.concurrent.atomic.AtomicLong) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) JobID(org.apache.flink.api.common.JobID) ListCheckpointed(org.apache.flink.streaming.api.checkpoint.ListCheckpointed) PartitionTestUtils(org.apache.flink.runtime.io.network.partition.PartitionTestUtils) Assert(org.junit.Assert) StreamSource(org.apache.flink.streaming.api.operators.StreamSource) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) CheckpointMetrics(org.apache.flink.runtime.checkpoint.CheckpointMetrics) NettyShuffleEnvironmentBuilder(org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder) NettyShuffleEnvironment(org.apache.flink.runtime.io.network.NettyShuffleEnvironment) CompletableFuture(java.util.concurrent.CompletableFuture) TaskStateSnapshot(org.apache.flink.runtime.checkpoint.TaskStateSnapshot) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) RecordOrEventCollectingResultPartitionWriter(org.apache.flink.runtime.io.network.api.writer.RecordOrEventCollectingResultPartitionWriter) ResultPartitionWriter(org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter) StreamTaskFinalCheckpointsTest.triggerCheckpoint(org.apache.flink.streaming.runtime.tasks.StreamTaskFinalCheckpointsTest.triggerCheckpoint) ResultPartition(org.apache.flink.runtime.io.network.partition.ResultPartition) AtomicLong(java.util.concurrent.atomic.AtomicLong) TestCheckpointResponder(org.apache.flink.runtime.taskmanager.TestCheckpointResponder) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 32 with NettyShuffleEnvironment

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

the class RecordWriterTest method createResultPartition.

public static ResultPartition createResultPartition(int bufferSize, int numSubpartitions) throws IOException {
    NettyShuffleEnvironment env = new NettyShuffleEnvironmentBuilder().setBufferSize(bufferSize).build();
    ResultPartition partition = createPartition(env, ResultPartitionType.PIPELINED, numSubpartitions);
    partition.setup();
    return partition;
}
Also used : NettyShuffleEnvironmentBuilder(org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder) NettyShuffleEnvironment(org.apache.flink.runtime.io.network.NettyShuffleEnvironment) ResultPartition(org.apache.flink.runtime.io.network.partition.ResultPartition)

Example 33 with NettyShuffleEnvironment

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

the class PipelinedApproximateSubpartitionTest method createResultPartition.

private static BufferWritingResultPartition createResultPartition() throws IOException {
    NettyShuffleEnvironment network = new NettyShuffleEnvironmentBuilder().setNumNetworkBuffers(10).setBufferSize(BUFFER_SIZE).build();
    ResultPartition resultPartition = createPartition(network, NoOpFileChannelManager.INSTANCE, ResultPartitionType.PIPELINED_APPROXIMATE, 2);
    resultPartition.setup();
    return (BufferWritingResultPartition) resultPartition;
}
Also used : NettyShuffleEnvironmentBuilder(org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder) NettyShuffleEnvironment(org.apache.flink.runtime.io.network.NettyShuffleEnvironment)

Aggregations

NettyShuffleEnvironment (org.apache.flink.runtime.io.network.NettyShuffleEnvironment)33 NettyShuffleEnvironmentBuilder (org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder)26 Test (org.junit.Test)24 InputChannelTestUtils.createRemoteInputChannel (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createRemoteInputChannel)9 Closer (org.apache.flink.shaded.guava30.com.google.common.io.Closer)9 InputChannelTestUtils.createLocalInputChannel (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createLocalInputChannel)8 TestingConnectionManager (org.apache.flink.runtime.io.network.TestingConnectionManager)7 Task (org.apache.flink.runtime.taskmanager.Task)7 Configuration (org.apache.flink.configuration.Configuration)6 ResultPartition (org.apache.flink.runtime.io.network.partition.ResultPartition)6 ResultPartitionID (org.apache.flink.runtime.io.network.partition.ResultPartitionID)6 IntermediateResultPartitionID (org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID)6 StreamConfig (org.apache.flink.streaming.api.graph.StreamConfig)6 ArrayList (java.util.ArrayList)4 List (java.util.List)4 SingleInputGate (org.apache.flink.runtime.io.network.partition.consumer.SingleInputGate)4 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)4 IOException (java.io.IOException)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 TypeSerializer (org.apache.flink.api.common.typeutils.TypeSerializer)3