pnowojski commented on a change in pull request #17968: URL: https://github.com/apache/flink/pull/17968#discussion_r763040594
########## File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/StopMode.java ########## @@ -0,0 +1,33 @@ +/* + * 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.streaming.runtime.tasks; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.streaming.api.operators.StreamOperator; + +/** + * Tells if the job is stopping because of consuming all data. {@link #DRAINED} means the job is + * stopping either with a stop-with-savepoint --drain or due to consuming all records in the source. + * A drained pipeline should call {@link StreamOperator#finish()} on all operators. + */ +@Internal +public enum StopMode { Review comment: Couldn't you provide the enum there as well? If needed, I think it could be defined in `flink-core`. ########## File path: flink-streaming-java/src/test/java/org/apache/flink/streaming/runtime/tasks/SourceStreamTaskTest.java ########## @@ -113,39 +107,6 @@ */ public class SourceStreamTaskTest extends SourceStreamTaskTestBase { - @Test - public void testInputEndedBeforeStopWithSavepointConfirmed() throws Exception { Review comment: Can you elaborate why are you removing so many different tests in different files? ########## File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/SourceOperator.java ########## @@ -305,23 +307,34 @@ public void open() throws Exception { @Override public void finish() throws Exception { + stopInternalServices(); + super.finish(); + + finished.complete(null); + } + + private void stopInternalServices() { if (eventTimeLogic != null) { eventTimeLogic.stopPeriodicWatermarkEmits(); } if (latencyMarerEmitter != null) { latencyMarerEmitter.close(); } - super.finish(); - - finished.complete(null); } - public CompletableFuture<Void> stop() { + public CompletableFuture<Void> stop(StopMode mode) { switch (operatingMode) { case OUTPUT_NOT_INITIALIZED: case READING: - this.operatingMode = OperatingMode.SOURCE_STOPPED; + this.operatingMode = + mode == StopMode.DRAINED + ? OperatingMode.SOURCE_DRAINED + : OperatingMode.SOURCE_STOPPED; availabilityHelper.forceStop(); + if (this.operatingMode == OperatingMode.SOURCE_STOPPED) { + stopInternalServices(); + return CompletableFuture.completedFuture(null); Review comment: For the sake of consistency, wouldn't it be better to return `finished` in this case as well and only complete this future in this call? ########## File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/SourceOperator.java ########## @@ -52,6 +52,7 @@ import org.apache.flink.streaming.runtime.io.PushingAsyncDataInput; Review comment: The 3rd commit should have better commit message explaining the change. ########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/io/PullingAsyncDataInput.java ########## @@ -65,4 +66,13 @@ * point */ boolean hasReceivedEndOfData(); + + /** + * Tells if we should drain all results in case we received {@link EndOfData} on all channels. + * If any of the upstream subtasks finished because of the stop-with-savepoint --no-drain, we + * should not drain the current task. See also {@code StopMode}. + * + * <p>We should check the {@link #hasReceivedEndOfData()} first. + */ + boolean shouldDrainOnEndOfData(); Review comment: Optional: Wouldn't it be better to have an three state `enum` here? As it is > <p>We should check the {@link #hasReceivedEndOfData()} first. is a bit strange. Especially the `UnionInputGate#shouldDrainOnEndOfData()`. ########## File path: flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/StopMode.java ########## @@ -0,0 +1,33 @@ +/* + * 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.streaming.runtime.tasks; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.streaming.api.operators.StreamOperator; + +/** + * Tells if the job is stopping because of consuming all data. {@link #DRAINED} means the job is + * stopping either with a stop-with-savepoint --drain or due to consuming all records in the source. + * A drained pipeline should call {@link StreamOperator#finish()} on all operators. + */ +@Internal +public enum StopMode { + DRAINED, + NO_DRAIN Review comment: `DRAINED` -> `DRAIN` I think would fit better in the context `stop(DRAIN)` and be more consistent? -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
