You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/08/20 08:30:55 UTC

[GitHub] [flink] zhuzhurk opened a new pull request #13205: [FLINK-17330[runtime] Merge cyclic dependent pipelined regions into one region

zhuzhurk opened a new pull request #13205:
URL: https://github.com/apache/flink/pull/13205


   ## What is the purpose of the change
   
   This PR changes regions building to merge cyclic dependent pipelined regions into one region.
   This is to avoid scheduling deadlocks due to cyclic dependencies.
   More details see FLINK-17330.
   
   ## Brief change log
   
     - *Added StronglyConnectedComponentsComputeUtils to find out cyclic dependent regions*
     - *Changed PipelinedRegionComputeUtil to merge cyclic dependent pipelined regions into one region*
   
   ## Verifying this change
   
     - *Added UT StronglyConnectedComponentsComputeUtilsTest*
     - *Added test case in PipelinedRegionComputeUtilTest to verify regions on the same cycles are merged*
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (yes / **no**)
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (yes / **no**)
     - The serializers: (yes / **no** / don't know)
     - The runtime per-record code paths (performance sensitive): (yes / **no** / don't know)
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn/Mesos, ZooKeeper: (**yes** / no / don't know)
     - The S3 file system connector: (yes / **no** / don't know)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (yes / **no**)
     - If yes, how is the feature documented? (**not applicable** / docs / JavaDocs / not documented)
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] zhuzhurk commented on a change in pull request #13205: [FLINK-17330[runtime] Merge cyclic dependent pipelined regions into one region

Posted by GitBox <gi...@apache.org>.
zhuzhurk commented on a change in pull request #13205:
URL: https://github.com/apache/flink/pull/13205#discussion_r475734143



##########
File path: flink-runtime/src/test/java/org/apache/flink/runtime/executiongraph/failover/flip1/StronglyConnectedComponentsComputeUtilsTest.java
##########
@@ -0,0 +1,216 @@
+/*
+ * 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.failover.flip1;
+
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Random;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import static org.apache.flink.runtime.executiongraph.failover.flip1.StronglyConnectedComponentsComputeUtils.computeStronglyConnectedComponents;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Unit tests for {@link StronglyConnectedComponentsComputeUtils}.
+ */
+public class StronglyConnectedComponentsComputeUtilsTest extends TestLogger {
+
+	@Test
+	public void testWithCycles() {
+		final List<List<Integer>> edges = Arrays.asList(
+			Arrays.asList(2, 3),
+			Arrays.asList(0),
+			Arrays.asList(1),
+			Arrays.asList(4),
+			Collections.emptyList());
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(5, edges);
+
+		final Set<Set<Integer>> expected = new HashSet<>();
+		expected.add(new HashSet<>(Arrays.asList(0, 1, 2)));
+		expected.add(Collections.singleton(3));
+		expected.add(Collections.singleton(4));
+
+		assertThat(result, is(expected));
+	}
+
+	@Test
+	public void testWithMultipleCycles() {
+		final List<List<Integer>> edges = Arrays.asList(
+			Arrays.asList(1),
+			Arrays.asList(2),
+			Arrays.asList(0),
+			Arrays.asList(1, 2, 4),
+			Arrays.asList(3, 5),
+			Arrays.asList(2, 6),
+			Arrays.asList(5),
+			Arrays.asList(4, 6, 7));
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(8, edges);
+
+		final Set<Set<Integer>> expected = new HashSet<>();
+		expected.add(new HashSet<>(Arrays.asList(0, 1, 2)));
+		expected.add(new HashSet<>(Arrays.asList(3, 4)));
+		expected.add(new HashSet<>(Arrays.asList(5, 6)));
+		expected.add(Collections.singleton(7));
+
+		assertThat(result, is(expected));
+	}
+
+	@Test
+	public void testWithConnectedCycles() {
+		final List<List<Integer>> edges = Arrays.asList(
+			Arrays.asList(1),
+			Arrays.asList(2, 4, 5),
+			Arrays.asList(3, 6),
+			Arrays.asList(2, 7),
+			Arrays.asList(0, 5),
+			Arrays.asList(6),
+			Arrays.asList(5),
+			Arrays.asList(3, 6));
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(8, edges);
+
+		final Set<Set<Integer>> expected = new HashSet<>();
+		expected.add(new HashSet<>(Arrays.asList(0, 1, 4)));
+		expected.add(new HashSet<>(Arrays.asList(2, 3, 7)));
+		expected.add(new HashSet<>(Arrays.asList(5, 6)));
+
+		assertThat(result, is(expected));
+	}
+
+	@Test
+	public void testWithNoEdge() {
+		final List<List<Integer>> edges = Arrays.asList(
+			Collections.emptyList(),
+			Collections.emptyList(),
+			Collections.emptyList(),
+			Collections.emptyList(),
+			Collections.emptyList());
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(5, edges);
+
+		final Set<Set<Integer>> expected = new HashSet<>();
+		expected.add(Collections.singleton(0));
+		expected.add(Collections.singleton(1));
+		expected.add(Collections.singleton(2));
+		expected.add(Collections.singleton(3));
+		expected.add(Collections.singleton(4));
+
+		assertThat(result, is(expected));
+	}
+
+	@Test
+	public void testWithNoCycle() {
+		final List<List<Integer>> edges = Arrays.asList(
+			Arrays.asList(1),
+			Arrays.asList(2),
+			Arrays.asList(3),
+			Arrays.asList(4),
+			Collections.emptyList());
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(5, edges);
+
+		final Set<Set<Integer>> expected = new HashSet<>();
+		expected.add(Collections.singleton(0));
+		expected.add(Collections.singleton(1));
+		expected.add(Collections.singleton(2));
+		expected.add(Collections.singleton(3));
+		expected.add(Collections.singleton(4));
+
+		assertThat(result, is(expected));
+	}
+
+	@Test
+	public void testLargeGraph() {
+		final int n = 100000;
+		final List<List<Integer>> edges = new ArrayList<>();
+		for (int i = 0; i < n; i++) {
+			edges.add(Collections.singletonList((i + 1) % n));
+		}
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(n, edges);
+
+		final Set<Integer> singleComponent = IntStream.range(0, n).boxed().collect(Collectors.toSet());
+
+		assertThat(result, is(Collections.singleton(singleComponent)));
+	}
+
+	@Test
+	public void testArbitraryGraph() {

Review comment:
       Ok. I will remove it.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] zhuzhurk commented on a change in pull request #13205: [FLINK-17330[runtime] Merge cyclic dependent pipelined regions into one region

Posted by GitBox <gi...@apache.org>.
zhuzhurk commented on a change in pull request #13205:
URL: https://github.com/apache/flink/pull/13205#discussion_r475390073



##########
File path: flink-runtime/src/test/java/org/apache/flink/runtime/executiongraph/failover/flip1/StronglyConnectedComponentsComputeUtilsTest.java
##########
@@ -0,0 +1,216 @@
+/*
+ * 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.failover.flip1;
+
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Random;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import static org.apache.flink.runtime.executiongraph.failover.flip1.StronglyConnectedComponentsComputeUtils.computeStronglyConnectedComponents;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Unit tests for {@link StronglyConnectedComponentsComputeUtils}.
+ */
+public class StronglyConnectedComponentsComputeUtilsTest extends TestLogger {
+
+	@Test
+	public void testWithCycles() {
+		final List<List<Integer>> edges = Arrays.asList(
+			Arrays.asList(2, 3),
+			Arrays.asList(0),
+			Arrays.asList(1),
+			Arrays.asList(4),
+			Collections.emptyList());
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(5, edges);
+
+		final Set<Set<Integer>> expected = new HashSet<>();
+		expected.add(new HashSet<>(Arrays.asList(0, 1, 2)));
+		expected.add(Collections.singleton(3));
+		expected.add(Collections.singleton(4));
+
+		assertThat(result, is(expected));
+	}
+
+	@Test
+	public void testWithMultipleCycles() {
+		final List<List<Integer>> edges = Arrays.asList(
+			Arrays.asList(1),
+			Arrays.asList(2),
+			Arrays.asList(0),
+			Arrays.asList(1, 2, 4),
+			Arrays.asList(3, 5),
+			Arrays.asList(2, 6),
+			Arrays.asList(5),
+			Arrays.asList(4, 6, 7));
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(8, edges);
+
+		final Set<Set<Integer>> expected = new HashSet<>();
+		expected.add(new HashSet<>(Arrays.asList(0, 1, 2)));
+		expected.add(new HashSet<>(Arrays.asList(3, 4)));
+		expected.add(new HashSet<>(Arrays.asList(5, 6)));
+		expected.add(Collections.singleton(7));
+
+		assertThat(result, is(expected));
+	}
+
+	@Test
+	public void testWithConnectedCycles() {
+		final List<List<Integer>> edges = Arrays.asList(
+			Arrays.asList(1),
+			Arrays.asList(2, 4, 5),
+			Arrays.asList(3, 6),
+			Arrays.asList(2, 7),
+			Arrays.asList(0, 5),
+			Arrays.asList(6),
+			Arrays.asList(5),
+			Arrays.asList(3, 6));
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(8, edges);
+
+		final Set<Set<Integer>> expected = new HashSet<>();
+		expected.add(new HashSet<>(Arrays.asList(0, 1, 4)));
+		expected.add(new HashSet<>(Arrays.asList(2, 3, 7)));
+		expected.add(new HashSet<>(Arrays.asList(5, 6)));
+
+		assertThat(result, is(expected));
+	}
+
+	@Test
+	public void testWithNoEdge() {
+		final List<List<Integer>> edges = Arrays.asList(
+			Collections.emptyList(),
+			Collections.emptyList(),
+			Collections.emptyList(),
+			Collections.emptyList(),
+			Collections.emptyList());
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(5, edges);
+
+		final Set<Set<Integer>> expected = new HashSet<>();
+		expected.add(Collections.singleton(0));
+		expected.add(Collections.singleton(1));
+		expected.add(Collections.singleton(2));
+		expected.add(Collections.singleton(3));
+		expected.add(Collections.singleton(4));
+
+		assertThat(result, is(expected));
+	}
+
+	@Test
+	public void testWithNoCycle() {
+		final List<List<Integer>> edges = Arrays.asList(
+			Arrays.asList(1),
+			Arrays.asList(2),
+			Arrays.asList(3),
+			Arrays.asList(4),
+			Collections.emptyList());
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(5, edges);
+
+		final Set<Set<Integer>> expected = new HashSet<>();
+		expected.add(Collections.singleton(0));
+		expected.add(Collections.singleton(1));
+		expected.add(Collections.singleton(2));
+		expected.add(Collections.singleton(3));
+		expected.add(Collections.singleton(4));
+
+		assertThat(result, is(expected));
+	}
+
+	@Test
+	public void testLargeGraph() {
+		final int n = 100000;
+		final List<List<Integer>> edges = new ArrayList<>();
+		for (int i = 0; i < n; i++) {
+			edges.add(Collections.singletonList((i + 1) % n));
+		}
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(n, edges);
+
+		final Set<Integer> singleComponent = IntStream.range(0, n).boxed().collect(Collectors.toSet());
+
+		assertThat(result, is(Collections.singleton(singleComponent)));
+	}
+
+	@Test
+	public void testArbitraryGraph() {

Review comment:
       I added it to cover any case that I am not aware.
   It's also fine for me to drop it if you feel like it, since I have already used it to test locally.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13205: [FLINK-17330[runtime] Merge cyclic dependent pipelined regions into one region

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13205:
URL: https://github.com/apache/flink/pull/13205#issuecomment-677463515


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "e11ffec55b9151857069d64c806b47cc98d9679d",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5739",
       "triggerID" : "e11ffec55b9151857069d64c806b47cc98d9679d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "b6ec9981ff3880e61df71fc37459026dcaafb950",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5810",
       "triggerID" : "b6ec9981ff3880e61df71fc37459026dcaafb950",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * e11ffec55b9151857069d64c806b47cc98d9679d Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5739) 
   * b6ec9981ff3880e61df71fc37459026dcaafb950 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5810) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] azagrebin commented on a change in pull request #13205: [FLINK-17330[runtime] Merge cyclic dependent pipelined regions into one region

Posted by GitBox <gi...@apache.org>.
azagrebin commented on a change in pull request #13205:
URL: https://github.com/apache/flink/pull/13205#discussion_r474212420



##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/failover/flip1/StronglyConnectedComponentsComputeUtils.java
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.failover.flip1;
+
+import org.apache.flink.api.java.tuple.Tuple2;
+
+import java.util.ArrayDeque;
+import java.util.Arrays;
+import java.util.Deque;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Utility for computing strongly connected components.
+ *
+ * <p>The computation is an implementation of Tarjan's algorithm.
+ *
+ * <p>Ref: https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm.
+ */
+public final class StronglyConnectedComponentsComputeUtils {
+
+	static Set<Set<Integer>> computeStronglyConnectedComponents(final int numVertex, final List<List<Integer>> outEdges) {
+		final Set<Set<Integer>> stronglyConnectedComponents = new HashSet<>();
+
+		final int[] vertexIndices = new int[numVertex];
+		Arrays.fill(vertexIndices, -1);
+
+		final int[] vertexLowLinks = new int[numVertex];
+		final Deque<Integer> stack = new ArrayDeque<>(numVertex);

Review comment:
       ```suggestion
   		final Deque<Integer> ccStack = new ArrayDeque<>(numVertex);
   ```

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/failover/flip1/StronglyConnectedComponentsComputeUtils.java
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.failover.flip1;
+
+import org.apache.flink.api.java.tuple.Tuple2;
+
+import java.util.ArrayDeque;
+import java.util.Arrays;
+import java.util.Deque;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Utility for computing strongly connected components.
+ *
+ * <p>The computation is an implementation of Tarjan's algorithm.
+ *
+ * <p>Ref: https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm.
+ */
+public final class StronglyConnectedComponentsComputeUtils {
+
+	static Set<Set<Integer>> computeStronglyConnectedComponents(final int numVertex, final List<List<Integer>> outEdges) {
+		final Set<Set<Integer>> stronglyConnectedComponents = new HashSet<>();
+
+		final int[] vertexIndices = new int[numVertex];
+		Arrays.fill(vertexIndices, -1);
+
+		final int[] vertexLowLinks = new int[numVertex];
+		final Deque<Integer> stack = new ArrayDeque<>(numVertex);
+		final boolean[] onStack = new boolean[numVertex];
+		final AtomicInteger indexCounter = new AtomicInteger(0);
+
+		for (int vertex = 0; vertex < numVertex; vertex++) {
+			if (vertexIndices[vertex] == -1) {
+				dfs(vertex, outEdges, vertexIndices, vertexLowLinks, stack, onStack, indexCounter, stronglyConnectedComponents);
+			}
+		}
+
+		return stronglyConnectedComponents;
+	}
+
+	private static void dfs(
+			final int rootVertex,
+			final List<List<Integer>> outEdges,
+			final int[] vertexIndices,
+			final int[] vertexLowLinks,
+			final Deque<Integer> stack,
+			final boolean[] onStack,
+			final AtomicInteger indexCounter,
+			final Set<Set<Integer>> stronglyConnectedComponents) {
+
+		final Deque<Tuple2<Integer, Integer>> loopStack = new ArrayDeque<>();
+		loopStack.add(new Tuple2<>(rootVertex, 0));
+
+		while (!loopStack.isEmpty()) {
+			Tuple2<Integer, Integer> tuple = loopStack.pollLast();
+			final int currentVertex = tuple.f0;
+			final int vertexLoopCount = tuple.f1;
+
+			if (vertexLoopCount == 0) {
+				vertexIndices[currentVertex] = indexCounter.get();
+				vertexLowLinks[currentVertex] = indexCounter.getAndIncrement();
+				stack.add(currentVertex);
+				onStack[currentVertex] = true;
+			} else if (vertexLoopCount > 0) {
+				final int successorVertex = outEdges.get(currentVertex).get(vertexLoopCount - 1);
+				vertexLowLinks[currentVertex] = Math.min(vertexLowLinks[currentVertex], vertexLowLinks[successorVertex]);
+			}
+
+			boolean visitSuccessorVertex = false;
+			for (int i = vertexLoopCount; i < outEdges.get(currentVertex).size(); i++) {
+				final int successorVertex = outEdges.get(currentVertex).get(i);
+				if (vertexIndices[successorVertex] == -1) {
+					loopStack.add(new Tuple2<>(currentVertex, i + 1));
+					loopStack.add(new Tuple2<>(successorVertex, 0));
+					visitSuccessorVertex = true;
+					break;
+				} else if (onStack[successorVertex]) {
+					vertexLowLinks[currentVertex] = Math.min(vertexLowLinks[currentVertex], vertexIndices[successorVertex]);
+				}
+			}
+
+			if (visitSuccessorVertex) {
+				continue;
+			}
+
+			if (vertexLowLinks[currentVertex] == vertexIndices[currentVertex]) {
+				final Set<Integer> scc = new HashSet<>();
+				while (onStack[currentVertex]) {
+					final int v = stack.pollLast();
+					onStack[v] = false;
+					scc.add(v);
+
+				}
+				stronglyConnectedComponents.add(scc);
+			}
+		}
+	}
+
+	private StronglyConnectedComponentsComputeUtils() {

Review comment:
       From what I saw before and discussed as code style, we usually put instance methods before static methods.

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/failover/flip1/StronglyConnectedComponentsComputeUtils.java
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.failover.flip1;
+
+import org.apache.flink.api.java.tuple.Tuple2;
+
+import java.util.ArrayDeque;
+import java.util.Arrays;
+import java.util.Deque;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Utility for computing strongly connected components.
+ *
+ * <p>The computation is an implementation of Tarjan's algorithm.
+ *
+ * <p>Ref: https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm.
+ */
+public final class StronglyConnectedComponentsComputeUtils {
+
+	static Set<Set<Integer>> computeStronglyConnectedComponents(final int numVertex, final List<List<Integer>> outEdges) {
+		final Set<Set<Integer>> stronglyConnectedComponents = new HashSet<>();
+
+		final int[] vertexIndices = new int[numVertex];
+		Arrays.fill(vertexIndices, -1);
+
+		final int[] vertexLowLinks = new int[numVertex];
+		final Deque<Integer> stack = new ArrayDeque<>(numVertex);
+		final boolean[] onStack = new boolean[numVertex];
+		final AtomicInteger indexCounter = new AtomicInteger(0);
+
+		for (int vertex = 0; vertex < numVertex; vertex++) {
+			if (vertexIndices[vertex] == -1) {
+				dfs(vertex, outEdges, vertexIndices, vertexLowLinks, stack, onStack, indexCounter, stronglyConnectedComponents);
+			}
+		}
+
+		return stronglyConnectedComponents;
+	}
+
+	private static void dfs(
+			final int rootVertex,
+			final List<List<Integer>> outEdges,
+			final int[] vertexIndices,
+			final int[] vertexLowLinks,
+			final Deque<Integer> stack,
+			final boolean[] onStack,
+			final AtomicInteger indexCounter,
+			final Set<Set<Integer>> stronglyConnectedComponents) {
+
+		final Deque<Tuple2<Integer, Integer>> loopStack = new ArrayDeque<>();
+		loopStack.add(new Tuple2<>(rootVertex, 0));
+
+		while (!loopStack.isEmpty()) {
+			Tuple2<Integer, Integer> tuple = loopStack.pollLast();
+			final int currentVertex = tuple.f0;
+			final int vertexLoopCount = tuple.f1;
+
+			if (vertexLoopCount == 0) {
+				vertexIndices[currentVertex] = indexCounter.get();

Review comment:
       I would add more comments for respective code blocks or maybe even additionally break the loop body into three methods/steps:
   ```
   startTraversingVertex
   finishTaversingOutEdge
   traverseOutEdges
   createConnectedComponent
   ```

##########
File path: flink-runtime/src/test/java/org/apache/flink/runtime/executiongraph/failover/flip1/StronglyConnectedComponentsComputeUtilsTest.java
##########
@@ -0,0 +1,216 @@
+/*
+ * 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.failover.flip1;
+
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Random;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import static org.apache.flink.runtime.executiongraph.failover.flip1.StronglyConnectedComponentsComputeUtils.computeStronglyConnectedComponents;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Unit tests for {@link StronglyConnectedComponentsComputeUtils}.
+ */
+public class StronglyConnectedComponentsComputeUtilsTest extends TestLogger {
+
+	@Test
+	public void testWithCycles() {
+		final List<List<Integer>> edges = Arrays.asList(
+			Arrays.asList(2, 3),
+			Arrays.asList(0),
+			Arrays.asList(1),
+			Arrays.asList(4),
+			Collections.emptyList());
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(5, edges);
+
+		final Set<Set<Integer>> expected = new HashSet<>();
+		expected.add(new HashSet<>(Arrays.asList(0, 1, 2)));
+		expected.add(Collections.singleton(3));
+		expected.add(Collections.singleton(4));
+
+		assertThat(result, is(expected));
+	}
+
+	@Test
+	public void testWithMultipleCycles() {
+		final List<List<Integer>> edges = Arrays.asList(
+			Arrays.asList(1),
+			Arrays.asList(2),
+			Arrays.asList(0),
+			Arrays.asList(1, 2, 4),
+			Arrays.asList(3, 5),
+			Arrays.asList(2, 6),
+			Arrays.asList(5),
+			Arrays.asList(4, 6, 7));
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(8, edges);
+
+		final Set<Set<Integer>> expected = new HashSet<>();
+		expected.add(new HashSet<>(Arrays.asList(0, 1, 2)));
+		expected.add(new HashSet<>(Arrays.asList(3, 4)));
+		expected.add(new HashSet<>(Arrays.asList(5, 6)));
+		expected.add(Collections.singleton(7));
+
+		assertThat(result, is(expected));
+	}
+
+	@Test
+	public void testWithConnectedCycles() {
+		final List<List<Integer>> edges = Arrays.asList(
+			Arrays.asList(1),
+			Arrays.asList(2, 4, 5),
+			Arrays.asList(3, 6),
+			Arrays.asList(2, 7),
+			Arrays.asList(0, 5),
+			Arrays.asList(6),
+			Arrays.asList(5),
+			Arrays.asList(3, 6));
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(8, edges);
+
+		final Set<Set<Integer>> expected = new HashSet<>();
+		expected.add(new HashSet<>(Arrays.asList(0, 1, 4)));
+		expected.add(new HashSet<>(Arrays.asList(2, 3, 7)));
+		expected.add(new HashSet<>(Arrays.asList(5, 6)));
+
+		assertThat(result, is(expected));
+	}
+
+	@Test
+	public void testWithNoEdge() {
+		final List<List<Integer>> edges = Arrays.asList(
+			Collections.emptyList(),
+			Collections.emptyList(),
+			Collections.emptyList(),
+			Collections.emptyList(),
+			Collections.emptyList());
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(5, edges);
+
+		final Set<Set<Integer>> expected = new HashSet<>();
+		expected.add(Collections.singleton(0));
+		expected.add(Collections.singleton(1));
+		expected.add(Collections.singleton(2));
+		expected.add(Collections.singleton(3));
+		expected.add(Collections.singleton(4));
+
+		assertThat(result, is(expected));
+	}
+
+	@Test
+	public void testWithNoCycle() {
+		final List<List<Integer>> edges = Arrays.asList(
+			Arrays.asList(1),
+			Arrays.asList(2),
+			Arrays.asList(3),
+			Arrays.asList(4),
+			Collections.emptyList());
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(5, edges);
+
+		final Set<Set<Integer>> expected = new HashSet<>();
+		expected.add(Collections.singleton(0));
+		expected.add(Collections.singleton(1));
+		expected.add(Collections.singleton(2));
+		expected.add(Collections.singleton(3));
+		expected.add(Collections.singleton(4));
+
+		assertThat(result, is(expected));
+	}
+
+	@Test
+	public void testLargeGraph() {
+		final int n = 100000;
+		final List<List<Integer>> edges = new ArrayList<>();
+		for (int i = 0; i < n; i++) {
+			edges.add(Collections.singletonList((i + 1) % n));
+		}
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(n, edges);
+
+		final Set<Integer> singleComponent = IntStream.range(0, n).boxed().collect(Collectors.toSet());
+
+		assertThat(result, is(Collections.singleton(singleComponent)));
+	}
+
+	@Test
+	public void testArbitraryGraph() {

Review comment:
       Do we need this random test? Is it not covered by separate deterministic cases in other tests?

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/failover/flip1/StronglyConnectedComponentsComputeUtils.java
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.failover.flip1;
+
+import org.apache.flink.api.java.tuple.Tuple2;
+
+import java.util.ArrayDeque;
+import java.util.Arrays;
+import java.util.Deque;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Utility for computing strongly connected components.
+ *
+ * <p>The computation is an implementation of Tarjan's algorithm.
+ *
+ * <p>Ref: https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm.
+ */
+public final class StronglyConnectedComponentsComputeUtils {
+
+	static Set<Set<Integer>> computeStronglyConnectedComponents(final int numVertex, final List<List<Integer>> outEdges) {
+		final Set<Set<Integer>> stronglyConnectedComponents = new HashSet<>();
+
+		final int[] vertexIndices = new int[numVertex];
+		Arrays.fill(vertexIndices, -1);
+
+		final int[] vertexLowLinks = new int[numVertex];
+		final Deque<Integer> stack = new ArrayDeque<>(numVertex);
+		final boolean[] onStack = new boolean[numVertex];
+		final AtomicInteger indexCounter = new AtomicInteger(0);
+
+		for (int vertex = 0; vertex < numVertex; vertex++) {
+			if (vertexIndices[vertex] == -1) {
+				dfs(vertex, outEdges, vertexIndices, vertexLowLinks, stack, onStack, indexCounter, stronglyConnectedComponents);
+			}
+		}
+
+		return stronglyConnectedComponents;
+	}
+
+	private static void dfs(
+			final int rootVertex,
+			final List<List<Integer>> outEdges,
+			final int[] vertexIndices,
+			final int[] vertexLowLinks,
+			final Deque<Integer> stack,
+			final boolean[] onStack,
+			final AtomicInteger indexCounter,
+			final Set<Set<Integer>> stronglyConnectedComponents) {
+
+		final Deque<Tuple2<Integer, Integer>> loopStack = new ArrayDeque<>();

Review comment:
       ```suggestion
   		final Deque<Tuple2<Integer, Integer>> dfsLoopStack = new ArrayDeque<>();
   ```

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/failover/flip1/StronglyConnectedComponentsComputeUtils.java
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.failover.flip1;
+
+import org.apache.flink.api.java.tuple.Tuple2;
+
+import java.util.ArrayDeque;
+import java.util.Arrays;
+import java.util.Deque;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Utility for computing strongly connected components.
+ *
+ * <p>The computation is an implementation of Tarjan's algorithm.
+ *
+ * <p>Ref: https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm.
+ */
+public final class StronglyConnectedComponentsComputeUtils {
+
+	static Set<Set<Integer>> computeStronglyConnectedComponents(final int numVertex, final List<List<Integer>> outEdges) {
+		final Set<Set<Integer>> stronglyConnectedComponents = new HashSet<>();
+
+		final int[] vertexIndices = new int[numVertex];
+		Arrays.fill(vertexIndices, -1);
+
+		final int[] vertexLowLinks = new int[numVertex];
+		final Deque<Integer> stack = new ArrayDeque<>(numVertex);
+		final boolean[] onStack = new boolean[numVertex];
+		final AtomicInteger indexCounter = new AtomicInteger(0);
+
+		for (int vertex = 0; vertex < numVertex; vertex++) {
+			if (vertexIndices[vertex] == -1) {
+				dfs(vertex, outEdges, vertexIndices, vertexLowLinks, stack, onStack, indexCounter, stronglyConnectedComponents);
+			}
+		}
+
+		return stronglyConnectedComponents;
+	}
+
+	private static void dfs(
+			final int rootVertex,
+			final List<List<Integer>> outEdges,
+			final int[] vertexIndices,
+			final int[] vertexLowLinks,
+			final Deque<Integer> stack,
+			final boolean[] onStack,
+			final AtomicInteger indexCounter,
+			final Set<Set<Integer>> stronglyConnectedComponents) {
+
+		final Deque<Tuple2<Integer, Integer>> loopStack = new ArrayDeque<>();
+		loopStack.add(new Tuple2<>(rootVertex, 0));
+
+		while (!loopStack.isEmpty()) {
+			Tuple2<Integer, Integer> tuple = loopStack.pollLast();
+			final int currentVertex = tuple.f0;
+			final int vertexLoopCount = tuple.f1;

Review comment:
       ```suggestion
   			final int vertexOutEdgeIndex = tuple.f1;
   ```




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13205: [FLINK-17330[runtime] Merge cyclic dependent pipelined regions into one region

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13205:
URL: https://github.com/apache/flink/pull/13205#issuecomment-677463515


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "e11ffec55b9151857069d64c806b47cc98d9679d",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5739",
       "triggerID" : "e11ffec55b9151857069d64c806b47cc98d9679d",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * e11ffec55b9151857069d64c806b47cc98d9679d Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5739) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] zhuzhurk merged pull request #13205: [FLINK-17330[runtime] Merge cyclic dependent pipelined regions into one region

Posted by GitBox <gi...@apache.org>.
zhuzhurk merged pull request #13205:
URL: https://github.com/apache/flink/pull/13205


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] azagrebin commented on a change in pull request #13205: [FLINK-17330[runtime] Merge cyclic dependent pipelined regions into one region

Posted by GitBox <gi...@apache.org>.
azagrebin commented on a change in pull request #13205:
URL: https://github.com/apache/flink/pull/13205#discussion_r475684085



##########
File path: flink-runtime/src/test/java/org/apache/flink/runtime/executiongraph/failover/flip1/StronglyConnectedComponentsComputeUtilsTest.java
##########
@@ -0,0 +1,216 @@
+/*
+ * 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.failover.flip1;
+
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Random;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import static org.apache.flink.runtime.executiongraph.failover.flip1.StronglyConnectedComponentsComputeUtils.computeStronglyConnectedComponents;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Unit tests for {@link StronglyConnectedComponentsComputeUtils}.
+ */
+public class StronglyConnectedComponentsComputeUtilsTest extends TestLogger {
+
+	@Test
+	public void testWithCycles() {
+		final List<List<Integer>> edges = Arrays.asList(
+			Arrays.asList(2, 3),
+			Arrays.asList(0),
+			Arrays.asList(1),
+			Arrays.asList(4),
+			Collections.emptyList());
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(5, edges);
+
+		final Set<Set<Integer>> expected = new HashSet<>();
+		expected.add(new HashSet<>(Arrays.asList(0, 1, 2)));
+		expected.add(Collections.singleton(3));
+		expected.add(Collections.singleton(4));
+
+		assertThat(result, is(expected));
+	}
+
+	@Test
+	public void testWithMultipleCycles() {
+		final List<List<Integer>> edges = Arrays.asList(
+			Arrays.asList(1),
+			Arrays.asList(2),
+			Arrays.asList(0),
+			Arrays.asList(1, 2, 4),
+			Arrays.asList(3, 5),
+			Arrays.asList(2, 6),
+			Arrays.asList(5),
+			Arrays.asList(4, 6, 7));
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(8, edges);
+
+		final Set<Set<Integer>> expected = new HashSet<>();
+		expected.add(new HashSet<>(Arrays.asList(0, 1, 2)));
+		expected.add(new HashSet<>(Arrays.asList(3, 4)));
+		expected.add(new HashSet<>(Arrays.asList(5, 6)));
+		expected.add(Collections.singleton(7));
+
+		assertThat(result, is(expected));
+	}
+
+	@Test
+	public void testWithConnectedCycles() {
+		final List<List<Integer>> edges = Arrays.asList(
+			Arrays.asList(1),
+			Arrays.asList(2, 4, 5),
+			Arrays.asList(3, 6),
+			Arrays.asList(2, 7),
+			Arrays.asList(0, 5),
+			Arrays.asList(6),
+			Arrays.asList(5),
+			Arrays.asList(3, 6));
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(8, edges);
+
+		final Set<Set<Integer>> expected = new HashSet<>();
+		expected.add(new HashSet<>(Arrays.asList(0, 1, 4)));
+		expected.add(new HashSet<>(Arrays.asList(2, 3, 7)));
+		expected.add(new HashSet<>(Arrays.asList(5, 6)));
+
+		assertThat(result, is(expected));
+	}
+
+	@Test
+	public void testWithNoEdge() {
+		final List<List<Integer>> edges = Arrays.asList(
+			Collections.emptyList(),
+			Collections.emptyList(),
+			Collections.emptyList(),
+			Collections.emptyList(),
+			Collections.emptyList());
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(5, edges);
+
+		final Set<Set<Integer>> expected = new HashSet<>();
+		expected.add(Collections.singleton(0));
+		expected.add(Collections.singleton(1));
+		expected.add(Collections.singleton(2));
+		expected.add(Collections.singleton(3));
+		expected.add(Collections.singleton(4));
+
+		assertThat(result, is(expected));
+	}
+
+	@Test
+	public void testWithNoCycle() {
+		final List<List<Integer>> edges = Arrays.asList(
+			Arrays.asList(1),
+			Arrays.asList(2),
+			Arrays.asList(3),
+			Arrays.asList(4),
+			Collections.emptyList());
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(5, edges);
+
+		final Set<Set<Integer>> expected = new HashSet<>();
+		expected.add(Collections.singleton(0));
+		expected.add(Collections.singleton(1));
+		expected.add(Collections.singleton(2));
+		expected.add(Collections.singleton(3));
+		expected.add(Collections.singleton(4));
+
+		assertThat(result, is(expected));
+	}
+
+	@Test
+	public void testLargeGraph() {
+		final int n = 100000;
+		final List<List<Integer>> edges = new ArrayList<>();
+		for (int i = 0; i < n; i++) {
+			edges.add(Collections.singletonList((i + 1) % n));
+		}
+
+		final Set<Set<Integer>> result = computeStronglyConnectedComponents(n, edges);
+
+		final Set<Integer> singleComponent = IntStream.range(0, n).boxed().collect(Collectors.toSet());
+
+		assertThat(result, is(Collections.singleton(singleComponent)));
+	}
+
+	@Test
+	public void testArbitraryGraph() {

Review comment:
       My concern was the complexity of the test to maintain in the code base. I think it is good to try this kind of test once but It seems to me that the random tests are usually hard to maintain and it is better to cover with the deterministic cases. I leave it up to you whether to keep it.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot commented on pull request #13205: [FLINK-17330[runtime] Merge cyclic dependent pipelined regions into one region

Posted by GitBox <gi...@apache.org>.
flinkbot commented on pull request #13205:
URL: https://github.com/apache/flink/pull/13205#issuecomment-677463515


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "e11ffec55b9151857069d64c806b47cc98d9679d",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "e11ffec55b9151857069d64c806b47cc98d9679d",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * e11ffec55b9151857069d64c806b47cc98d9679d UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13205: [FLINK-17330[runtime] Merge cyclic dependent pipelined regions into one region

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13205:
URL: https://github.com/apache/flink/pull/13205#issuecomment-677463515


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "e11ffec55b9151857069d64c806b47cc98d9679d",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5739",
       "triggerID" : "e11ffec55b9151857069d64c806b47cc98d9679d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "b6ec9981ff3880e61df71fc37459026dcaafb950",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5810",
       "triggerID" : "b6ec9981ff3880e61df71fc37459026dcaafb950",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8617ce6c0c5e0b4e8ba01aae58b1ef5cff2f02e6",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5827",
       "triggerID" : "8617ce6c0c5e0b4e8ba01aae58b1ef5cff2f02e6",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 8617ce6c0c5e0b4e8ba01aae58b1ef5cff2f02e6 Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5827) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot commented on pull request #13205: [FLINK-17330[runtime] Merge cyclic dependent pipelined regions into one region

Posted by GitBox <gi...@apache.org>.
flinkbot commented on pull request #13205:
URL: https://github.com/apache/flink/pull/13205#issuecomment-677459348


   Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
   to review your pull request. We will use this comment to track the progress of the review.
   
   
   ## Automated Checks
   Last check on commit e11ffec55b9151857069d64c806b47cc98d9679d (Thu Aug 20 08:33:48 UTC 2020)
   
   **Warnings:**
    * No documentation files were touched! Remember to keep the Flink docs up to date!
   
   
   <sub>Mention the bot in a comment to re-run the automated checks.</sub>
   ## Review Progress
   
   * ❓ 1. The [description] looks good.
   * ❓ 2. There is [consensus] that the contribution should go into to Flink.
   * ❓ 3. Needs [attention] from.
   * ❓ 4. The change fits into the overall [architecture].
   * ❓ 5. Overall code [quality] is good.
   
   Please see the [Pull Request Review Guide](https://flink.apache.org/contributing/reviewing-prs.html) for a full explanation of the review process.<details>
    The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot approve description` to approve one or more aspects (aspects: `description`, `consensus`, `architecture` and `quality`)
    - `@flinkbot approve all` to approve all aspects
    - `@flinkbot approve-until architecture` to approve everything until `architecture`
    - `@flinkbot attention @username1 [@username2 ..]` to require somebody's attention
    - `@flinkbot disapprove architecture` to remove an approval you gave earlier
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] zhuzhurk commented on a change in pull request #13205: [FLINK-17330[runtime] Merge cyclic dependent pipelined regions into one region

Posted by GitBox <gi...@apache.org>.
zhuzhurk commented on a change in pull request #13205:
URL: https://github.com/apache/flink/pull/13205#discussion_r475388935



##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/failover/flip1/StronglyConnectedComponentsComputeUtils.java
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.failover.flip1;
+
+import org.apache.flink.api.java.tuple.Tuple2;
+
+import java.util.ArrayDeque;
+import java.util.Arrays;
+import java.util.Deque;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Utility for computing strongly connected components.
+ *
+ * <p>The computation is an implementation of Tarjan's algorithm.
+ *
+ * <p>Ref: https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm.
+ */
+public final class StronglyConnectedComponentsComputeUtils {
+
+	static Set<Set<Integer>> computeStronglyConnectedComponents(final int numVertex, final List<List<Integer>> outEdges) {
+		final Set<Set<Integer>> stronglyConnectedComponents = new HashSet<>();
+
+		final int[] vertexIndices = new int[numVertex];
+		Arrays.fill(vertexIndices, -1);
+
+		final int[] vertexLowLinks = new int[numVertex];
+		final Deque<Integer> stack = new ArrayDeque<>(numVertex);

Review comment:
       renamed it as `visitingStack`




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13205: [FLINK-17330[runtime] Merge cyclic dependent pipelined regions into one region

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13205:
URL: https://github.com/apache/flink/pull/13205#issuecomment-677463515


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "e11ffec55b9151857069d64c806b47cc98d9679d",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5739",
       "triggerID" : "e11ffec55b9151857069d64c806b47cc98d9679d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "b6ec9981ff3880e61df71fc37459026dcaafb950",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5810",
       "triggerID" : "b6ec9981ff3880e61df71fc37459026dcaafb950",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8617ce6c0c5e0b4e8ba01aae58b1ef5cff2f02e6",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "8617ce6c0c5e0b4e8ba01aae58b1ef5cff2f02e6",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * b6ec9981ff3880e61df71fc37459026dcaafb950 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5810) 
   * 8617ce6c0c5e0b4e8ba01aae58b1ef5cff2f02e6 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13205: [FLINK-17330[runtime] Merge cyclic dependent pipelined regions into one region

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13205:
URL: https://github.com/apache/flink/pull/13205#issuecomment-677463515


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "e11ffec55b9151857069d64c806b47cc98d9679d",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5739",
       "triggerID" : "e11ffec55b9151857069d64c806b47cc98d9679d",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * e11ffec55b9151857069d64c806b47cc98d9679d Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5739) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13205: [FLINK-17330[runtime] Merge cyclic dependent pipelined regions into one region

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13205:
URL: https://github.com/apache/flink/pull/13205#issuecomment-677463515


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "e11ffec55b9151857069d64c806b47cc98d9679d",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5739",
       "triggerID" : "e11ffec55b9151857069d64c806b47cc98d9679d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "b6ec9981ff3880e61df71fc37459026dcaafb950",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "b6ec9981ff3880e61df71fc37459026dcaafb950",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * e11ffec55b9151857069d64c806b47cc98d9679d Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5739) 
   * b6ec9981ff3880e61df71fc37459026dcaafb950 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13205: [FLINK-17330[runtime] Merge cyclic dependent pipelined regions into one region

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13205:
URL: https://github.com/apache/flink/pull/13205#issuecomment-677463515


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "e11ffec55b9151857069d64c806b47cc98d9679d",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5739",
       "triggerID" : "e11ffec55b9151857069d64c806b47cc98d9679d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "b6ec9981ff3880e61df71fc37459026dcaafb950",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5810",
       "triggerID" : "b6ec9981ff3880e61df71fc37459026dcaafb950",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * b6ec9981ff3880e61df71fc37459026dcaafb950 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5810) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [flink] flinkbot edited a comment on pull request #13205: [FLINK-17330[runtime] Merge cyclic dependent pipelined regions into one region

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13205:
URL: https://github.com/apache/flink/pull/13205#issuecomment-677463515


   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "e11ffec55b9151857069d64c806b47cc98d9679d",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5739",
       "triggerID" : "e11ffec55b9151857069d64c806b47cc98d9679d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "b6ec9981ff3880e61df71fc37459026dcaafb950",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5810",
       "triggerID" : "b6ec9981ff3880e61df71fc37459026dcaafb950",
       "triggerType" : "PUSH"
     }, {
       "hash" : "8617ce6c0c5e0b4e8ba01aae58b1ef5cff2f02e6",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5827",
       "triggerID" : "8617ce6c0c5e0b4e8ba01aae58b1ef5cff2f02e6",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * b6ec9981ff3880e61df71fc37459026dcaafb950 Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5810) 
   * 8617ce6c0c5e0b4e8ba01aae58b1ef5cff2f02e6 Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=5827) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>


----------------------------------------------------------------
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:
users@infra.apache.org