AHeise commented on code in PR #25456: URL: https://github.com/apache/flink/pull/25456#discussion_r1806188639
########## flink-runtime/src/main/java/org/apache/flink/streaming/runtime/translators/GlobalCommitterTransformationTranslator.java: ########## @@ -0,0 +1,128 @@ +/* + * 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.translators; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.api.common.typeinfo.Types; +import org.apache.flink.api.dag.Transformation; +import org.apache.flink.streaming.api.connector.sink2.CommittableMessage; +import org.apache.flink.streaming.api.connector.sink2.GlobalCommitterOperator; +import org.apache.flink.streaming.api.datastream.DataStream; +import org.apache.flink.streaming.api.graph.TransformationTranslator; +import org.apache.flink.streaming.api.operators.ChainingStrategy; +import org.apache.flink.streaming.api.operators.StreamOperatorFactory; +import org.apache.flink.streaming.api.transformations.GlobalCommitterTransform; +import org.apache.flink.streaming.api.transformations.OneInputTransformation; +import org.apache.flink.streaming.api.transformations.PhysicalTransformation; +import org.apache.flink.streaming.runtime.operators.sink.CommitterOperatorFactory; +import org.apache.flink.streaming.runtime.operators.sink.SinkWriterOperatorFactory; + +import java.util.ArrayDeque; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Queue; +import java.util.Set; + +import static org.apache.flink.streaming.api.connector.sink2.StandardSinkTopologies.GLOBAL_COMMITTER_TRANSFORMATION_NAME; + +/** + * A {@link TransformationTranslator} for the {@link GlobalCommitterOperator}. The main purpose is + * to detect whether we set {@link GlobalCommitterOperator#commitOnInput} or not. + */ +@Internal +public class GlobalCommitterTransformationTranslator<CommT> + implements TransformationTranslator<Void, GlobalCommitterTransform<CommT>> { + + @Override + public Collection<Integer> translateForBatch( + GlobalCommitterTransform<CommT> transformation, Context context) { + return translateInternal(transformation, true); + } + + @Override + public Collection<Integer> translateForStreaming( + GlobalCommitterTransform<CommT> transformation, Context context) { + return translateInternal(transformation, false); + } + + private Collection<Integer> translateInternal( + GlobalCommitterTransform<CommT> globalCommitterTransform, boolean batch) { + DataStream<CommittableMessage<CommT>> inputStream = + globalCommitterTransform.getInputStream(); + boolean checkpointingEnabled = + inputStream + .getExecutionEnvironment() + .getCheckpointConfig() + .isCheckpointingEnabled(); + boolean commitOnInput = batch || !checkpointingEnabled || hasUpstreamCommitter(inputStream); + + // Create a global shuffle and add the global committer with parallelism 1. + final PhysicalTransformation<Void> transformation = + (PhysicalTransformation<Void>) + inputStream + .global() + .transform( + GLOBAL_COMMITTER_TRANSFORMATION_NAME, + Types.VOID, + new GlobalCommitterOperator<>( + globalCommitterTransform.getCommitterFactory(), + globalCommitterTransform.getCommittableSerializer(), + commitOnInput)) + .getTransformation(); + transformation.setChainingStrategy(ChainingStrategy.ALWAYS); + transformation.setName(GLOBAL_COMMITTER_TRANSFORMATION_NAME); + transformation.setParallelism(1); + transformation.setMaxParallelism(1); + return Collections.emptyList(); + } + + /** + * Looks for a committer in the pipeline and aborts on writer. The GlobalCommitter behaves + * differently if there is a committer after the writer. + */ + private static boolean hasUpstreamCommitter(DataStream<?> ds) { Review Comment: That's a good point. What happens is: if it finds a committer, the new optimized behavior applies. If it doesn't the old unoptimized behavior is used. So the question is what happens if you have a committer and do stuff afterwards in such a way that the committer suddenly is not doing 2PC anymore until the data reaches the global committer. I haven't been able to find such a scenario. You could have a writer->committer->union->global committer where the union is also directly fed by the writer->union->global committer but even then the output of the committer participated in 2PC. In short, I'm convinced it's safe that any upstream committer does 2PC already and the global committer can simply piggyback. Remember that parts of the change is that the 3PC commit protocol that we currently have is is not working properly with final checkpoints. With this fix, we get a working 2PC and "only" continue to violate endInput. -- 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