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/04/22 10:26:57 UTC

[GitHub] [flink] zhuzhurk commented on a change in pull request #11857: [FLINK-17180][runtime] Implement SchedulingPipelinedRegion interface

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



##########
File path: flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adapter/DefaultSchedulingPipelinedRegionTest.java
##########
@@ -0,0 +1,127 @@
+/*
+ * 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.scheduler.adapter;
+
+import org.apache.flink.api.common.InputDependencyConstraint;
+import org.apache.flink.runtime.execution.ExecutionState;
+import org.apache.flink.runtime.executiongraph.ExecutionGraph;
+import org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import org.apache.flink.runtime.jobgraph.DistributionPattern;
+import org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID;
+import org.apache.flink.runtime.jobgraph.JobVertex;
+import org.apache.flink.runtime.jobgraph.JobVertexID;
+import org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID;
+import org.apache.flink.util.IterableUtils;
+import org.apache.flink.util.TestLogger;
+
+import org.apache.flink.shaded.guava18.com.google.common.collect.Iterables;
+
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.sameInstance;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+/**
+ * Unit tests for {@link DefaultSchedulingPipelinedRegion}.
+ */
+public class DefaultSchedulingPipelinedRegionTest extends TestLogger {
+
+	@Test
+	public void gettingUnknownVertexThrowsException() {
+		final DefaultSchedulingPipelinedRegion pipelinedRegion = new DefaultSchedulingPipelinedRegion(Collections.emptySet());
+		final ExecutionVertexID unknownVertexId = new ExecutionVertexID(new JobVertexID(), 0);
+		try {
+			pipelinedRegion.getVertex(unknownVertexId);
+			fail("Expected exception not thrown");
+		} catch (IllegalArgumentException e) {
+			assertThat(e.getMessage(), containsString(unknownVertexId + " not found"));
+		}
+	}
+
+	@Test
+	public void returnsVertices() {
+		final DefaultExecutionVertex vertex = new DefaultExecutionVertex(
+			new ExecutionVertexID(new JobVertexID(), 0),
+			Collections.emptyList(),
+			() -> ExecutionState.CREATED,
+			InputDependencyConstraint.ANY);
+
+		final Set<DefaultExecutionVertex> vertices = Collections.singleton(vertex);
+		final DefaultSchedulingPipelinedRegion pipelinedRegion = new DefaultSchedulingPipelinedRegion(vertices);
+		final Iterator<DefaultExecutionVertex> vertexIterator = pipelinedRegion.getVertices().iterator();
+
+		assertThat(vertexIterator.hasNext(), is(true));
+		assertThat(vertexIterator.next(), is(sameInstance(vertex)));
+		assertThat(vertexIterator.hasNext(), is(false));
+	}
+
+	/**
+	 * Tests if the consumed inputs of the pipelined regions are computed
+	 * correctly using the Job graph below.
+	 * <pre>
+	 *          c
+	 *        /  X
+	 * a -+- b   e
+	 *       \  /
+	 *        d
+	 * </pre>
+	 * Pipelined regions: {a}, {b, c, d, e}
+	 */
+	@Test
+	public void returnsIncidentBlockingPartitions() throws Exception {
+		final JobVertex a = ExecutionGraphTestUtils.createNoOpVertex(1);
+		final JobVertex b = ExecutionGraphTestUtils.createNoOpVertex(1);
+		final JobVertex c = ExecutionGraphTestUtils.createNoOpVertex(1);
+		final JobVertex d = ExecutionGraphTestUtils.createNoOpVertex(1);
+		final JobVertex e = ExecutionGraphTestUtils.createNoOpVertex(1);
+
+		b.connectNewDataSetAsInput(a, DistributionPattern.POINTWISE, ResultPartitionType.BLOCKING);
+		c.connectNewDataSetAsInput(b, DistributionPattern.POINTWISE, ResultPartitionType.PIPELINED);
+		d.connectNewDataSetAsInput(b, DistributionPattern.POINTWISE, ResultPartitionType.PIPELINED);
+		e.connectNewDataSetAsInput(c, DistributionPattern.POINTWISE, ResultPartitionType.BLOCKING);
+		e.connectNewDataSetAsInput(d, DistributionPattern.POINTWISE, ResultPartitionType.PIPELINED);
+
+		final ExecutionGraph simpleTestGraph = ExecutionGraphTestUtils.createSimpleTestGraph(a, b, c, d, e);
+		final DefaultExecutionTopology topology = new DefaultExecutionTopology(simpleTestGraph);
+
+		final DefaultSchedulingPipelinedRegion firstPipelinedRegion = topology.getPipelinedRegionOfVertex(new ExecutionVertexID(a.getID(), 0));
+		final DefaultSchedulingPipelinedRegion secondPipelinedRegion = topology.getPipelinedRegionOfVertex(new ExecutionVertexID(e.getID(), 0));
+
+		final DefaultExecutionVertex vertexB0 = topology.getVertex(new ExecutionVertexID(b.getID(), 0));
+		final IntermediateResultPartitionID b0ConsumedResultPartition = Iterables.getOnlyElement(vertexB0.getConsumedResults()).getId();
+
+		final Set<IntermediateResultPartitionID> secondPipelinedRegionConsumedResults = IterableUtils.toStream(secondPipelinedRegion.getConsumedResults())
+			.map(DefaultResultPartition::getId)
+			.collect(Collectors.toSet());
+
+		assertThat(firstPipelinedRegion.getConsumedResults().iterator().hasNext(), is(false));
+		assertThat(secondPipelinedRegionConsumedResults, contains(b0ConsumedResultPartition));

Review comment:
       maybe assert equals to verify that the result partition produced by c0 is not a consumed partition of the second region?

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/failover/flip1/partitionrelease/RegionPartitionReleaseStrategy.java
##########
@@ -41,15 +39,13 @@
 import static org.apache.flink.util.Preconditions.checkState;
 
 /**
- * Releases blocking intermediate result partitions that are incident to a {@link PipelinedRegion},
+ * Releases blocking intermediate result partitions that are incident to a {@link SchedulingPipelinedRegion},
  * as soon as the region's execution vertices are finished.
  */
 public class RegionPartitionReleaseStrategy implements PartitionReleaseStrategy {

Review comment:
       Nice that it is simplified a lot!

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adapter/DefaultSchedulingPipelinedRegion.java
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.scheduler.adapter;
+
+import org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID;
+import org.apache.flink.runtime.scheduler.strategy.SchedulingPipelinedRegion;
+import org.apache.flink.util.Preconditions;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Default implementation of {@link SchedulingPipelinedRegion}.
+ */
+public class DefaultSchedulingPipelinedRegion implements SchedulingPipelinedRegion {
+
+	private final Map<ExecutionVertexID, DefaultExecutionVertex> executionVertices;
+
+	private Set<DefaultResultPartition> consumedResults;
+
+	public DefaultSchedulingPipelinedRegion(Set<DefaultExecutionVertex> defaultExecutionVertices) {
+		Preconditions.checkNotNull(defaultExecutionVertices);
+
+		this.executionVertices = new HashMap<>();
+		for (DefaultExecutionVertex executionVertex : defaultExecutionVertices) {
+			this.executionVertices.put(executionVertex.getId(), executionVertex);
+		}
+	}
+
+	@Override
+	public Iterable<DefaultExecutionVertex> getVertices() {
+		return Collections.unmodifiableCollection(executionVertices.values());
+	}
+
+	@Override
+	public DefaultExecutionVertex getVertex(final ExecutionVertexID vertexId) {
+		final DefaultExecutionVertex executionVertex = executionVertices.get(vertexId);
+		if (executionVertex == null) {
+			throw new IllegalArgumentException(String.format(
+				"Execution vertex %s not found in pipelined region",
+				vertexId));
+		}
+		return executionVertex;
+	}
+
+	@Override
+	public Iterable<DefaultResultPartition> getConsumedResults() {
+		if (consumedResults == null) {
+			initializeConsumedResults();
+		}
+		return consumedResults;
+	}
+
+	private void initializeConsumedResults() {
+		Set<DefaultResultPartition> consumedResults = new HashSet<>();

Review comment:
       nit: final

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/failover/flip1/partitionrelease/RegionPartitionReleaseStrategy.java
##########
@@ -41,15 +39,13 @@
 import static org.apache.flink.util.Preconditions.checkState;
 
 /**
- * Releases blocking intermediate result partitions that are incident to a {@link PipelinedRegion},
+ * Releases blocking intermediate result partitions that are incident to a {@link SchedulingPipelinedRegion},
  * as soon as the region's execution vertices are finished.
  */
 public class RegionPartitionReleaseStrategy implements PartitionReleaseStrategy {

Review comment:
       But seems the constructor and factory are not reworked to not build regions by themselves?

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/failover/flip1/RestartPipelinedRegionFailoverStrategy.java
##########
@@ -84,34 +77,8 @@ public RestartPipelinedRegionFailoverStrategy(
 		ResultPartitionAvailabilityChecker resultPartitionAvailabilityChecker) {
 
 		this.topology = checkNotNull(topology);
-		this.regions = Collections.newSetFromMap(new IdentityHashMap<>());
-		this.vertexToRegionMap = new HashMap<>();
 		this.resultPartitionAvailabilityChecker = new RegionFailoverResultPartitionAvailabilityChecker(
 			resultPartitionAvailabilityChecker);
-
-		// build regions based on the given topology
-		LOG.info("Start building failover regions.");
-		buildFailoverRegions();
-	}
-	// ------------------------------------------------------------------------
-	//  region building
-	// ------------------------------------------------------------------------
-
-	private void buildFailoverRegions() {
-		final Set<Set<SchedulingExecutionVertex>> distinctRegions =
-			PipelinedRegionComputeUtil.computePipelinedRegions(topology);
-
-		// creating all the failover regions and register them
-		for (Set<SchedulingExecutionVertex> regionVertices : distinctRegions) {
-			LOG.debug("Creating a failover region with {} vertices.", regionVertices.size());
-			final FailoverRegion failoverRegion = new FailoverRegion(regionVertices);
-			regions.add(failoverRegion);
-			for (SchedulingExecutionVertex vertex : regionVertices) {
-				vertexToRegionMap.put(vertex.getId(), failoverRegion);
-			}
-		}
-
-		LOG.info("Created {} failover regions.", regions.size());

Review comment:
       How about adding such logs in DefaultExecutionTopology region building?
   This can be helpful to diagnose whether regions are built as expected. 
   And maybe also one line for region building start so that users can see how much time the region building takes.




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