lindong28 commented on code in PR #22670: URL: https://github.com/apache/flink/pull/22670#discussion_r1244817411
########## flink-tests/src/test/java/org/apache/flink/test/checkpointing/ImmediateCheckpointingAfterAllTasksFinishedITCase.java: ########## @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.test.checkpointing; + +import org.apache.flink.api.common.restartstrategy.RestartStrategies; +import org.apache.flink.api.common.typeinfo.Types; +import org.apache.flink.api.connector.sink2.Sink; +import org.apache.flink.api.connector.sink2.SinkWriter; +import org.apache.flink.core.execution.SavepointFormatType; +import org.apache.flink.runtime.jobgraph.JobGraph; +import org.apache.flink.runtime.jobgraph.JobVertex; +import org.apache.flink.runtime.jobgraph.SavepointRestoreSettings; +import org.apache.flink.runtime.minicluster.MiniCluster; +import org.apache.flink.runtime.minicluster.MiniClusterConfiguration; +import org.apache.flink.runtime.state.StateSnapshotContext; +import org.apache.flink.runtime.testutils.CommonTestUtils; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.streaming.api.functions.source.RichSourceFunction; +import org.apache.flink.streaming.api.graph.StreamGraph; +import org.apache.flink.streaming.api.operators.AbstractStreamOperator; +import org.apache.flink.streaming.api.operators.OneInputStreamOperator; +import org.apache.flink.streaming.runtime.streamrecord.StreamRecord; +import org.apache.flink.test.util.AbstractTestBase; + +import org.junit.Assert; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +/** + * Tests an immediate checkpoint should be triggered right after all tasks reached the end of data. + */ +public class ImmediateCheckpointingAfterAllTasksFinishedITCase extends AbstractTestBase { + private static final int SMALL_SOURCE_NUM_RECORDS = 20; + private static final int BIG_SOURCE_NUM_RECORDS = 100; + + private StreamExecutionEnvironment env; + + @TempDir private java.nio.file.Path tmpDir; + + @BeforeEach + public void setUp() { + env = StreamExecutionEnvironment.getExecutionEnvironment(); + env.setRestartStrategy(RestartStrategies.noRestart()); + env.enableCheckpointing(Long.MAX_VALUE - 1); + } + + @ParameterizedTest + @ValueSource(ints = {1, 4}) + public void testImmediateCheckpointing(int parallelism) throws Exception { Review Comment: It seems that this test should pass regardless of whether we notify JM of task's end-of-data. Do we need this test? ########## flink-tests/src/test/java/org/apache/flink/test/checkpointing/ImmediateCheckpointingAfterAllTasksFinishedITCase.java: ########## @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.test.checkpointing; + +import org.apache.flink.api.common.restartstrategy.RestartStrategies; +import org.apache.flink.api.common.typeinfo.Types; +import org.apache.flink.api.connector.sink2.Sink; +import org.apache.flink.api.connector.sink2.SinkWriter; +import org.apache.flink.core.execution.SavepointFormatType; +import org.apache.flink.runtime.jobgraph.JobGraph; +import org.apache.flink.runtime.jobgraph.JobVertex; +import org.apache.flink.runtime.jobgraph.SavepointRestoreSettings; +import org.apache.flink.runtime.minicluster.MiniCluster; +import org.apache.flink.runtime.minicluster.MiniClusterConfiguration; +import org.apache.flink.runtime.state.StateSnapshotContext; +import org.apache.flink.runtime.testutils.CommonTestUtils; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.streaming.api.functions.source.RichSourceFunction; +import org.apache.flink.streaming.api.graph.StreamGraph; +import org.apache.flink.streaming.api.operators.AbstractStreamOperator; +import org.apache.flink.streaming.api.operators.OneInputStreamOperator; +import org.apache.flink.streaming.runtime.streamrecord.StreamRecord; +import org.apache.flink.test.util.AbstractTestBase; + +import org.junit.Assert; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +/** + * Tests an immediate checkpoint should be triggered right after all tasks reached the end of data. + */ +public class ImmediateCheckpointingAfterAllTasksFinishedITCase extends AbstractTestBase { + private static final int SMALL_SOURCE_NUM_RECORDS = 20; + private static final int BIG_SOURCE_NUM_RECORDS = 100; + + private StreamExecutionEnvironment env; + + @TempDir private java.nio.file.Path tmpDir; + + @BeforeEach + public void setUp() { + env = StreamExecutionEnvironment.getExecutionEnvironment(); + env.setRestartStrategy(RestartStrategies.noRestart()); + env.enableCheckpointing(Long.MAX_VALUE - 1); + } + + @ParameterizedTest + @ValueSource(ints = {1, 4}) + public void testImmediateCheckpointing(int parallelism) throws Exception { + env.setParallelism(parallelism); + StreamGraph streamGraph = getStreamGraph(env); + env.execute(streamGraph); + } + + @ParameterizedTest + @ValueSource(ints = {1, 4}) + public void testRestoreAfterSomeTasksFinished(int parallelism) throws Exception { + env.setParallelism(parallelism); + + final MiniClusterConfiguration cfg = + new MiniClusterConfiguration.Builder() + .withRandomPorts() + .setNumTaskManagers(1) + .setNumSlotsPerTaskManager(4) + .build(); + try (MiniCluster miniCluster = new MiniCluster(cfg)) { + miniCluster.start(); + + env.enableCheckpointing(100); Review Comment: Can you explain why we set checkpoint interval to 100 ms here? Would it be more intuitive to use the same checkpointing interval (e.g. Long.MAX_VALUE - 1) before and after this job is restarted? ########## flink-tests/src/test/java/org/apache/flink/test/checkpointing/ImmediateCheckpointingAfterAllTasksFinishedITCase.java: ########## @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.test.checkpointing; + +import org.apache.flink.api.common.restartstrategy.RestartStrategies; +import org.apache.flink.api.common.typeinfo.Types; +import org.apache.flink.api.connector.sink2.Sink; +import org.apache.flink.api.connector.sink2.SinkWriter; +import org.apache.flink.core.execution.SavepointFormatType; +import org.apache.flink.runtime.jobgraph.JobGraph; +import org.apache.flink.runtime.jobgraph.JobVertex; +import org.apache.flink.runtime.jobgraph.SavepointRestoreSettings; +import org.apache.flink.runtime.minicluster.MiniCluster; +import org.apache.flink.runtime.minicluster.MiniClusterConfiguration; +import org.apache.flink.runtime.state.StateSnapshotContext; +import org.apache.flink.runtime.testutils.CommonTestUtils; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.streaming.api.functions.source.RichSourceFunction; +import org.apache.flink.streaming.api.graph.StreamGraph; +import org.apache.flink.streaming.api.operators.AbstractStreamOperator; +import org.apache.flink.streaming.api.operators.OneInputStreamOperator; +import org.apache.flink.streaming.runtime.streamrecord.StreamRecord; +import org.apache.flink.test.util.AbstractTestBase; + +import org.junit.Assert; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +/** + * Tests an immediate checkpoint should be triggered right after all tasks reached the end of data. + */ +public class ImmediateCheckpointingAfterAllTasksFinishedITCase extends AbstractTestBase { Review Comment: Given that most class in this package use `checkpoint` rather than `checkpointing`, how about renaming this class as `CheckpointAfterAllTasksFinishedITCase` for simplicity? ########## flink-tests/src/test/java/org/apache/flink/test/checkpointing/ImmediateCheckpointingAfterAllTasksFinishedITCase.java: ########## @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.test.checkpointing; + +import org.apache.flink.api.common.restartstrategy.RestartStrategies; +import org.apache.flink.api.common.typeinfo.Types; +import org.apache.flink.api.connector.sink2.Sink; +import org.apache.flink.api.connector.sink2.SinkWriter; +import org.apache.flink.core.execution.SavepointFormatType; +import org.apache.flink.runtime.jobgraph.JobGraph; +import org.apache.flink.runtime.jobgraph.JobVertex; +import org.apache.flink.runtime.jobgraph.SavepointRestoreSettings; +import org.apache.flink.runtime.minicluster.MiniCluster; +import org.apache.flink.runtime.minicluster.MiniClusterConfiguration; +import org.apache.flink.runtime.state.StateSnapshotContext; +import org.apache.flink.runtime.testutils.CommonTestUtils; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.streaming.api.functions.source.RichSourceFunction; +import org.apache.flink.streaming.api.graph.StreamGraph; +import org.apache.flink.streaming.api.operators.AbstractStreamOperator; +import org.apache.flink.streaming.api.operators.OneInputStreamOperator; +import org.apache.flink.streaming.runtime.streamrecord.StreamRecord; +import org.apache.flink.test.util.AbstractTestBase; + +import org.junit.Assert; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +/** + * Tests an immediate checkpoint should be triggered right after all tasks reached the end of data. + */ +public class ImmediateCheckpointingAfterAllTasksFinishedITCase extends AbstractTestBase { + private static final int SMALL_SOURCE_NUM_RECORDS = 20; + private static final int BIG_SOURCE_NUM_RECORDS = 100; + + private StreamExecutionEnvironment env; + + @TempDir private java.nio.file.Path tmpDir; + + @BeforeEach + public void setUp() { + env = StreamExecutionEnvironment.getExecutionEnvironment(); + env.setRestartStrategy(RestartStrategies.noRestart()); + env.enableCheckpointing(Long.MAX_VALUE - 1); + } + + @ParameterizedTest + @ValueSource(ints = {1, 4}) Review Comment: Can you explain why we need to run this test with two different parallelism choices? Note that most checkpoint tests in this package do not re-run tests with different parallelism. It is probably better to only introduce the extra complexity when we need it. ########## flink-tests/src/test/java/org/apache/flink/test/checkpointing/ImmediateCheckpointingAfterAllTasksFinishedITCase.java: ########## @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.test.checkpointing; + +import org.apache.flink.api.common.restartstrategy.RestartStrategies; +import org.apache.flink.api.common.typeinfo.Types; +import org.apache.flink.api.connector.sink2.Sink; +import org.apache.flink.api.connector.sink2.SinkWriter; +import org.apache.flink.core.execution.SavepointFormatType; +import org.apache.flink.runtime.jobgraph.JobGraph; +import org.apache.flink.runtime.jobgraph.JobVertex; +import org.apache.flink.runtime.jobgraph.SavepointRestoreSettings; +import org.apache.flink.runtime.minicluster.MiniCluster; +import org.apache.flink.runtime.minicluster.MiniClusterConfiguration; +import org.apache.flink.runtime.state.StateSnapshotContext; +import org.apache.flink.runtime.testutils.CommonTestUtils; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.streaming.api.functions.source.RichSourceFunction; +import org.apache.flink.streaming.api.graph.StreamGraph; +import org.apache.flink.streaming.api.operators.AbstractStreamOperator; +import org.apache.flink.streaming.api.operators.OneInputStreamOperator; +import org.apache.flink.streaming.runtime.streamrecord.StreamRecord; +import org.apache.flink.test.util.AbstractTestBase; + +import org.junit.Assert; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +/** + * Tests an immediate checkpoint should be triggered right after all tasks reached the end of data. + */ +public class ImmediateCheckpointingAfterAllTasksFinishedITCase extends AbstractTestBase { + private static final int SMALL_SOURCE_NUM_RECORDS = 20; + private static final int BIG_SOURCE_NUM_RECORDS = 100; + + private StreamExecutionEnvironment env; + + @TempDir private java.nio.file.Path tmpDir; + + @BeforeEach + public void setUp() { + env = StreamExecutionEnvironment.getExecutionEnvironment(); + env.setRestartStrategy(RestartStrategies.noRestart()); + env.enableCheckpointing(Long.MAX_VALUE - 1); + } + + @ParameterizedTest + @ValueSource(ints = {1, 4}) + public void testImmediateCheckpointing(int parallelism) throws Exception { + env.setParallelism(parallelism); + StreamGraph streamGraph = getStreamGraph(env); + env.execute(streamGraph); + } + + @ParameterizedTest + @ValueSource(ints = {1, 4}) + public void testRestoreAfterSomeTasksFinished(int parallelism) throws Exception { + env.setParallelism(parallelism); + + final MiniClusterConfiguration cfg = + new MiniClusterConfiguration.Builder() + .withRandomPorts() + .setNumTaskManagers(1) + .setNumSlotsPerTaskManager(4) + .build(); + try (MiniCluster miniCluster = new MiniCluster(cfg)) { + miniCluster.start(); + + env.enableCheckpointing(100); + JobGraph jobGraph = getStreamGraph(env).getJobGraph(); + miniCluster.submitJob(jobGraph).get(); + + CommonTestUtils.waitForSubtasksToFinish( + miniCluster, + jobGraph.getJobID(), + findVertexByName(jobGraph, "Source: smallSource").getID(), + false); + + String savepointPath = + miniCluster + .triggerSavepoint( Review Comment: I suppose the goal is to stop the after some (but not all) subtasks have finished. But it is not clear whether the test does this. It is possible that all vertexes have stopped by the time we stop the job. How about we do the following to ensure that the job is after some (but not all) subtasks have finished: - SourceB waits for an in-memory flag to be set to true before emitting all its data. - Set the flag to true after the job is restarted. ########## flink-tests/src/test/java/org/apache/flink/test/checkpointing/ImmediateCheckpointingAfterAllTasksFinishedITCase.java: ########## @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.test.checkpointing; + +import org.apache.flink.api.common.restartstrategy.RestartStrategies; +import org.apache.flink.api.common.typeinfo.Types; +import org.apache.flink.api.connector.sink2.Sink; +import org.apache.flink.api.connector.sink2.SinkWriter; +import org.apache.flink.core.execution.SavepointFormatType; +import org.apache.flink.runtime.jobgraph.JobGraph; +import org.apache.flink.runtime.jobgraph.JobVertex; +import org.apache.flink.runtime.jobgraph.SavepointRestoreSettings; +import org.apache.flink.runtime.minicluster.MiniCluster; +import org.apache.flink.runtime.minicluster.MiniClusterConfiguration; +import org.apache.flink.runtime.state.StateSnapshotContext; +import org.apache.flink.runtime.testutils.CommonTestUtils; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.streaming.api.functions.source.RichSourceFunction; +import org.apache.flink.streaming.api.graph.StreamGraph; +import org.apache.flink.streaming.api.operators.AbstractStreamOperator; +import org.apache.flink.streaming.api.operators.OneInputStreamOperator; +import org.apache.flink.streaming.runtime.streamrecord.StreamRecord; +import org.apache.flink.test.util.AbstractTestBase; + +import org.junit.Assert; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +/** + * Tests an immediate checkpoint should be triggered right after all tasks reached the end of data. + */ +public class ImmediateCheckpointingAfterAllTasksFinishedITCase extends AbstractTestBase { + private static final int SMALL_SOURCE_NUM_RECORDS = 20; + private static final int BIG_SOURCE_NUM_RECORDS = 100; + + private StreamExecutionEnvironment env; + + @TempDir private java.nio.file.Path tmpDir; + + @BeforeEach + public void setUp() { + env = StreamExecutionEnvironment.getExecutionEnvironment(); + env.setRestartStrategy(RestartStrategies.noRestart()); + env.enableCheckpointing(Long.MAX_VALUE - 1); + } + + @ParameterizedTest + @ValueSource(ints = {1, 4}) + public void testImmediateCheckpointing(int parallelism) throws Exception { + env.setParallelism(parallelism); + StreamGraph streamGraph = getStreamGraph(env); + env.execute(streamGraph); + } + + @ParameterizedTest + @ValueSource(ints = {1, 4}) + public void testRestoreAfterSomeTasksFinished(int parallelism) throws Exception { Review Comment: Can you additionally check the correctness of the job output similar to what other tests (e.g. CheckpointRestoreWithUidHashITCase) do? ########## flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/StateWithExecutionGraph.java: ########## @@ -195,6 +200,18 @@ void declineCheckpoint(DeclineCheckpoint decline) { executionGraphHandler.declineCheckpoint(decline); } + void notifyEndOfData(ExecutionAttemptID executionAttemptID) { + CheckpointCoordinatorConfiguration checkpointCoordinatorConfiguration = + executionGraph.getCheckpointCoordinatorConfiguration(); + if (checkpointCoordinatorConfiguration != null Review Comment: Should we also check job type and whether checkpoint is enabled, for consistency with `SchedulerBase#notifyEndOfData`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org