zhuzhurk commented on a change in pull request #14868:
URL: https://github.com/apache/flink/pull/14868#discussion_r585416743



##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/EdgeManagerBuildUtil.java
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.runtime.executiongraph;
+
+import org.apache.flink.runtime.jobgraph.DistributionPattern;
+import org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID;
+import org.apache.flink.runtime.scheduler.strategy.ConsumedPartitionGroup;
+import org.apache.flink.runtime.scheduler.strategy.ConsumerVertexGroup;
+import org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/** Utilities for building {@link EdgeManager}. */
+public class EdgeManagerBuildUtil {
+
+    /**
+     * Calculate the connections between {@link ExecutionJobVertex} and {@link 
IntermediateResult}
+     * based on the {@link DistributionPattern}. The connection information is 
stored in the {@link
+     * EdgeManager}.
+     */
+    public static void connectVertexToResult(

Review comment:
       Seems it can be package private.

##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/ExecutionVertex.java
##########
@@ -321,107 +323,11 @@ public ExecutionGraph getExecutionGraph() {
     //  Graph building
     // 
--------------------------------------------------------------------------------------------
 
-    public void connectSource(
-            int inputNumber, IntermediateResult source, JobEdge edge, int 
consumerNumber) {
-
-        final DistributionPattern pattern = edge.getDistributionPattern();
-        final IntermediateResultPartition[] sourcePartitions = 
source.getPartitions();
-
-        ExecutionEdge[] edges;
-
-        switch (pattern) {
-            case POINTWISE:
-                edges = connectPointwise(sourcePartitions, inputNumber);
-                break;
-
-            case ALL_TO_ALL:
-                edges = connectAllToAll(sourcePartitions, inputNumber);
-                break;
-
-            default:
-                throw new RuntimeException("Unrecognized distribution 
pattern.");
-        }
-
-        inputEdges[inputNumber] = edges;
-
-        // add the consumers to the source
-        // for now (until the receiver initiated handshake is in place), we 
need to register the
-        // edges as the execution graph
-        for (ExecutionEdge ee : edges) {
-            ee.getSource().addConsumer(ee, consumerNumber);
-        }
-    }
-
-    private ExecutionEdge[] connectAllToAll(
-            IntermediateResultPartition[] sourcePartitions, int inputNumber) {
-        ExecutionEdge[] edges = new ExecutionEdge[sourcePartitions.length];
-
-        for (int i = 0; i < sourcePartitions.length; i++) {
-            IntermediateResultPartition irp = sourcePartitions[i];
-            edges[i] = new ExecutionEdge(irp, this, inputNumber);
-        }
-
-        return edges;
-    }
-
-    private ExecutionEdge[] connectPointwise(
-            IntermediateResultPartition[] sourcePartitions, int inputNumber) {
-        final int numSources = sourcePartitions.length;
-        final int parallelism = getTotalNumberOfParallelSubtasks();
-
-        // simple case same number of sources as targets
-        if (numSources == parallelism) {
-            return new ExecutionEdge[] {
-                new ExecutionEdge(sourcePartitions[subTaskIndex], this, 
inputNumber)
-            };
-        } else if (numSources < parallelism) {
-
-            int sourcePartition;
-
-            // check if the pattern is regular or irregular
-            // we use int arithmetics for regular, and floating point with 
rounding for irregular
-            if (parallelism % numSources == 0) {
-                // same number of targets per source
-                int factor = parallelism / numSources;
-                sourcePartition = subTaskIndex / factor;
-            } else {
-                // different number of targets per source
-                float factor = ((float) parallelism) / numSources;
-                sourcePartition = (int) (subTaskIndex / factor);
-            }

Review comment:
       I think the previous code which handles case `XXX % YYY == 0` is an 
unnecessarily complication and we can simplify it a bit. The result should be 
the same and `PointwiseTest#testPointwiseConnectionSequence` is added to ensure 
this.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to