GJL commented on a change in pull request #8922: [FLINK-12876][runtime] Add an 
adapter of region failover NG for legacy scheduler
URL: https://github.com/apache/flink/pull/8922#discussion_r298536587
 
 

 ##########
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/executiongraph/AdaptedRestartPipelinedRegionStrategyNGFailoverTest.java
 ##########
 @@ -0,0 +1,513 @@
+/*
+ * 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.api.common.JobID;
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.runtime.akka.AkkaUtils;
+import org.apache.flink.runtime.clusterframework.types.SlotProfile;
+import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor;
+import org.apache.flink.runtime.concurrent.FutureUtils;
+import org.apache.flink.runtime.concurrent.ManuallyTriggeredScheduledExecutor;
+import org.apache.flink.runtime.execution.ExecutionState;
+import 
org.apache.flink.runtime.executiongraph.failover.AdaptedRestartPipelinedRegionStrategyNG;
+import 
org.apache.flink.runtime.executiongraph.restart.InfiniteDelayRestartStrategy;
+import org.apache.flink.runtime.executiongraph.restart.NoRestartStrategy;
+import org.apache.flink.runtime.executiongraph.restart.RestartStrategy;
+import org.apache.flink.runtime.executiongraph.utils.SimpleSlotProvider;
+import org.apache.flink.runtime.instance.SlotSharingGroupId;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionID;
+import org.apache.flink.runtime.io.network.partition.ResultPartitionType;
+import 
org.apache.flink.runtime.io.network.partition.consumer.PartitionConnectionException;
+import org.apache.flink.runtime.jobgraph.DistributionPattern;
+import org.apache.flink.runtime.jobgraph.JobGraph;
+import org.apache.flink.runtime.jobgraph.JobStatus;
+import org.apache.flink.runtime.jobgraph.JobVertex;
+import org.apache.flink.runtime.jobgraph.ScheduleMode;
+import org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable;
+import org.apache.flink.runtime.jobmanager.scheduler.ScheduledUnit;
+import org.apache.flink.runtime.jobmaster.LogicalSlot;
+import org.apache.flink.runtime.jobmaster.SlotRequestId;
+import org.apache.flink.runtime.jobmaster.slotpool.SlotProvider;
+import org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID;
+import org.apache.flink.runtime.testingUtils.TestingUtils;
+import org.apache.flink.util.FlinkException;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.annotation.Nullable;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeoutException;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Tests for {@link AdaptedRestartPipelinedRegionStrategyNG} failover handling.
+ */
+public class AdaptedRestartPipelinedRegionStrategyNGFailoverTest extends 
TestLogger {
+
+       private static final JobID TEST_JOB_ID = new JobID();
+
+       private ComponentMainThreadExecutor componentMainThreadExecutor;
+
+       private FailingSlotProviderDecorator slotProvider;
+
+       private ManuallyTriggeredScheduledExecutor manualMainThreadExecutor;
+
+       @Before
+       public void setUp() {
+               manualMainThreadExecutor = new 
ManuallyTriggeredScheduledExecutor();
+               componentMainThreadExecutor = new 
ScheduledExecutorToComponentMainThreadExecutorAdapter(manualMainThreadExecutor, 
Thread.currentThread());
+               slotProvider = new FailingSlotProviderDecorator(new 
SimpleSlotProvider(TEST_JOB_ID, 14));
+       }
+
+       /**
+        * Tests for region failover for job in EAGER mode.
+        * This applies to streaming job, with no BLOCKING edge.
+        * <pre>
+        *     (v11) ---> (v21)
+        *
+        *     (v12) ---> (v22)
+        *
+        *            ^
+        *            |
+        *       (pipelined)
+        * </pre>
+        */
+       @Test
+       public void testRegionFailoverInEagerMode() throws Exception {
+               // create a streaming job graph with EAGER schedule mode
+               final JobGraph jobGraph = createStreamingJobGraph();
+               final ExecutionGraph eg = createExecutionGraph(jobGraph);
+
+               final Iterator<ExecutionVertex> vertexIterator = 
eg.getAllExecutionVertices().iterator();
+               final ExecutionVertex ev11 = vertexIterator.next();
+               final ExecutionVertex ev12 = vertexIterator.next();
+               final ExecutionVertex ev21 = vertexIterator.next();
+               final ExecutionVertex ev22 = vertexIterator.next();
+
+               // trigger task failure of ev11
+               // vertices { ev11, ev21 } should be affected
+               ev11.getCurrentExecutionAttempt().fail(new Exception("Test 
Exception"));
+               manualMainThreadExecutor.triggerAll();
+
+               // verify vertex states and complete cancellation
+               assertVertexInState(ExecutionState.FAILED, ev11);
+               assertVertexInState(ExecutionState.DEPLOYING, ev12);
+               assertVertexInState(ExecutionState.CANCELING, ev21);
+               assertVertexInState(ExecutionState.DEPLOYING, ev22);
+               ev21.getCurrentExecutionAttempt().completeCancelling();
+               manualMainThreadExecutor.triggerAll();
+
+               // verify vertex states
+               // in eager mode, all affected vertices should be scheduled in 
failover
+               assertVertexInState(ExecutionState.DEPLOYING, ev11);
+               assertVertexInState(ExecutionState.DEPLOYING, ev12);
+               assertVertexInState(ExecutionState.DEPLOYING, ev21);
+               assertVertexInState(ExecutionState.DEPLOYING, ev22);
+
+               // verify attempt number
+               assertEquals(1, 
ev11.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev12.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(1, 
ev21.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev22.getCurrentExecutionAttempt().getAttemptNumber());
+       }
+
+       /**
+        * Tests for scenario where a task fails for its own error, in which 
case the
+        * region containing the failed task and its consumer regions should be 
restarted.
+        * <pre>
+        *     (v11) -+-> (v21)
+        *            x
+        *     (v12) -+-> (v22)
+        *
+        *            ^
+        *            |
+        *        (blocking)
+        * </pre>
+        */
+       @Test
+       public void testRegionFailoverForRegionInternalErrorsInLazyMode() 
throws Exception {
+               final JobGraph jobGraph = createBatchJobGraph();
+               final ExecutionGraph eg = createExecutionGraph(jobGraph);
+
+               final Iterator<ExecutionVertex> vertexIterator = 
eg.getAllExecutionVertices().iterator();
+               final ExecutionVertex ev11 = vertexIterator.next();
+               final ExecutionVertex ev12 = vertexIterator.next();
+               final ExecutionVertex ev21 = vertexIterator.next();
+               final ExecutionVertex ev22 = vertexIterator.next();
+
+               // trigger task failure of ev11
+               // regions {ev11}, {ev21}, {ev22} should be affected
+               ev11.getCurrentExecutionAttempt().fail(new Exception("Test 
Exception"));
+               manualMainThreadExecutor.triggerAll();
+
+               // verify vertex states
+               // only vertices with consumable inputs can be scheduled
+               assertVertexInState(ExecutionState.DEPLOYING, ev11);
+               assertVertexInState(ExecutionState.DEPLOYING, ev12);
+               assertVertexInState(ExecutionState.CREATED, ev21);
+               assertVertexInState(ExecutionState.CREATED, ev22);
+
+               // verify attempt number
+               assertEquals(1, 
ev11.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev12.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(1, 
ev21.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(1, 
ev22.getCurrentExecutionAttempt().getAttemptNumber());
+       }
+
+       /**
+        * Tests that the failure is properly propagated to underlying strategy
+        * to calculate tasks to restart.
+        * <pre>
+        *     (v11) -+-> (v21)
+        *            x
+        *     (v12) -+-> (v22)
+        *
+        *            ^
+        *            |
+        *        (blocking)
+        * </pre>
+        */
+       @Test
+       public void testFailurePropagationToUnderlyingStrategy() throws 
Exception {
+               final JobGraph jobGraph = createBatchJobGraph();
+               final ExecutionGraph eg = createExecutionGraph(jobGraph);
+
+               final TestAdaptedRestartPipelinedRegionStrategyNG 
failoverStrategy =
+                       (TestAdaptedRestartPipelinedRegionStrategyNG) 
eg.getFailoverStrategy();
+
+               final Iterator<ExecutionVertex> vertexIterator = 
eg.getAllExecutionVertices().iterator();
+               final ExecutionVertex ev11 = vertexIterator.next();
+               final ExecutionVertex ev12 = vertexIterator.next();
+               final ExecutionVertex ev21 = vertexIterator.next();
+
+               // trigger downstream regions to schedule
+               componentMainThreadExecutor.execute(() -> {
+                       // finish upstream regions to trigger scheduling of 
downstream regions
+                       ev11.getCurrentExecutionAttempt().markFinished();
+                       ev12.getCurrentExecutionAttempt().markFinished();
+               });
+
+               // trigger task failure of ev21 on consuming data from ev11
+               Exception taskFailureCause = new PartitionConnectionException(
+                       new ResultPartitionID(
+                               
ev11.getProducedPartitions().keySet().iterator().next(),
+                               
ev11.getCurrentExecutionAttempt().getAttemptId()),
+                       new Exception("Test failure"));
+               ev21.getCurrentExecutionAttempt().fail(taskFailureCause);
+               manualMainThreadExecutor.triggerAll();
+
+               assertThat(failoverStrategy.getLastTasksToCancel(), 
containsInAnyOrder(
+                       new ExecutionVertexID(ev11.getJobvertexId(), 0),
+                       new ExecutionVertexID(ev21.getJobvertexId(), 0),
+                       new ExecutionVertexID(ev21.getJobvertexId(), 1)));
 
 Review comment:
   true, I am waiting for `ev22.getID()`

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


With regards,
Apache Git Services

Reply via email to