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

 ##########
 File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/executiongraph/AdaptedRestartPipelinedRegionStrategyNGFailoverTest.java
 ##########
 @@ -0,0 +1,763 @@
+/*
+ * 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.metrics.groups.UnregisteredMetricsGroup;
+import org.apache.flink.mock.Whitebox;
+import org.apache.flink.runtime.JobException;
+import org.apache.flink.runtime.akka.AkkaUtils;
+import org.apache.flink.runtime.checkpoint.CheckpointCoordinator;
+import org.apache.flink.runtime.checkpoint.CheckpointCoordinatorTest;
+import org.apache.flink.runtime.checkpoint.CheckpointException;
+import org.apache.flink.runtime.checkpoint.CheckpointMetrics;
+import org.apache.flink.runtime.checkpoint.CheckpointProperties;
+import org.apache.flink.runtime.checkpoint.CheckpointRetentionPolicy;
+import org.apache.flink.runtime.checkpoint.CheckpointStatsTracker;
+import org.apache.flink.runtime.checkpoint.OperatorSubtaskState;
+import org.apache.flink.runtime.checkpoint.PendingCheckpoint;
+import org.apache.flink.runtime.checkpoint.StandaloneCheckpointIDCounter;
+import org.apache.flink.runtime.checkpoint.StandaloneCompletedCheckpointStore;
+import org.apache.flink.runtime.checkpoint.TaskStateSnapshot;
+import org.apache.flink.runtime.execution.ExecutionState;
+import 
org.apache.flink.runtime.executiongraph.failover.AdaptedRestartPipelinedRegionStrategyNG;
+import org.apache.flink.runtime.executiongraph.failover.FailoverStrategy;
+import 
org.apache.flink.runtime.executiongraph.failover.FailoverStrategy.Factory;
+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.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.JobVertexID;
+import org.apache.flink.runtime.jobgraph.OperatorID;
+import org.apache.flink.runtime.jobgraph.ScheduleMode;
+import org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable;
+import 
org.apache.flink.runtime.jobgraph.tasks.CheckpointCoordinatorConfiguration;
+import org.apache.flink.runtime.messages.checkpoint.AcknowledgeCheckpoint;
+import org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID;
+import org.apache.flink.runtime.state.CheckpointStorageCoordinatorView;
+import org.apache.flink.runtime.state.OperatorStateHandle;
+import org.apache.flink.runtime.state.memory.MemoryStateBackend;
+import org.apache.flink.runtime.testingUtils.TestingUtils;
+import org.apache.flink.util.FlinkException;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+
+/**
+ * Tests for {@link AdaptedRestartPipelinedRegionStrategyNG} failover handling.
+ */
+public class AdaptedRestartPipelinedRegionStrategyNGFailoverTest extends 
TestLogger {
+
+       @ClassRule
+       public static final TestingComponentMainThreadExecutor.Resource 
EXECUTOR_RESOURCE =
+               new TestingComponentMainThreadExecutor.Resource();
+
+       private final TestingComponentMainThreadExecutor testMainThreadUtil =
+               EXECUTOR_RESOURCE.getComponentMainThreadTestExecutor();
+
+       /**
+        * 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>
+        * 2 regions. Each has 2 pipelined connected vertices.
+        */
+       @Test
+       public void testRegionFailoverInEagerMode() throws Exception {
+
+               // create a streaming job graph with EAGER schedule mode
+               final JobGraph jobGraph = createStreamingJobGraph();
+               final long checkpointId = 42L;
+               final ExecutionGraph eg = createExecutionGraph(jobGraph, 
checkpointId);
+
+               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();
+
+               // verify initial state
+               assertVertexInState(ExecutionState.DEPLOYING, ev11);
+               assertVertexInState(ExecutionState.DEPLOYING, ev12);
+               assertVertexInState(ExecutionState.DEPLOYING, ev21);
+               assertVertexInState(ExecutionState.DEPLOYING, ev22);
+
+               // verify initial attempt number
+               assertEquals(0, 
ev11.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev12.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev21.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev22.getCurrentExecutionAttempt().getAttemptNumber());
+
+               // trigger task failure of ev11
+               // vertices { ev11, ev21, ev22 } should be affected
+               testMainThreadUtil.execute(() -> 
ev11.getCurrentExecutionAttempt().fail(new Exception("Test Exception")));
+
+               // verify vertex states and complete cancellation
+               assertVertexInState(ExecutionState.FAILED, ev11);
+               assertVertexInState(ExecutionState.DEPLOYING, ev12);
+               assertVertexInState(ExecutionState.CANCELING, ev21);
+               assertVertexInState(ExecutionState.DEPLOYING, ev22);
+               testMainThreadUtil.execute(() -> 
ev21.getCurrentExecutionAttempt().completeCancelling());
+
+               // 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 scenes that 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) -+-> (v31) --> (v41)
+        *                      x
+        *     (v12) --> (v22) -+-> (v32) --> (v42)
+        *
+        *                      ^
+        *                      |
+        *                  (blocking)
+        * </pre>
+        * 4 regions. Each region has 2 pipelined connected vertices.
+        */
+       @Test
+       public void testRegionFailoverForRegionInternalErrorsInLazyMode() 
throws Exception {
+
+               // create a batch job graph with LAZY_FROM_SOURCES schedule mode
+               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();
+               final ExecutionVertex ev31 = vertexIterator.next();
+               final ExecutionVertex ev32 = vertexIterator.next();
+               final ExecutionVertex ev41 = vertexIterator.next();
+               final ExecutionVertex ev42 = vertexIterator.next();
+
+               // trigger ev21 scheduling on data from ev11 is consumable
+               testMainThreadUtil.execute(() -> 
eg.scheduleOrUpdateConsumers(new ResultPartitionID(
+                       ev11.getProducedPartitions().keySet().iterator().next(),
+                       ev11.getCurrentExecutionAttempt().getAttemptId())));
+
+               // verify initial state
+               assertVertexInState(ExecutionState.DEPLOYING, ev11);
+               assertVertexInState(ExecutionState.DEPLOYING, ev12);
+               assertVertexInState(ExecutionState.DEPLOYING, ev21);
+               assertVertexInState(ExecutionState.CREATED, ev22);
+               assertVertexInState(ExecutionState.CREATED, ev31);
+               assertVertexInState(ExecutionState.CREATED, ev32);
+               assertVertexInState(ExecutionState.CREATED, ev41);
+               assertVertexInState(ExecutionState.CREATED, ev42);
+
+               // verify initial attempt number
+               assertEquals(0, 
ev11.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev12.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev21.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev22.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev31.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev32.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev41.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev42.getCurrentExecutionAttempt().getAttemptNumber());
+
+               // trigger task failure of ev11
+               // vertices { ev11, ev21, ev31, ev32, ev41, ev42} should be 
affected
+               testMainThreadUtil.execute(() -> 
ev11.getCurrentExecutionAttempt().fail(new Exception("Test Exception")));
+
+               // verify vertex states and complete cancellation
+               assertVertexInState(ExecutionState.FAILED, ev11);
+               assertVertexInState(ExecutionState.DEPLOYING, ev12);
+               assertVertexInState(ExecutionState.CANCELING, ev21);
+               assertVertexInState(ExecutionState.CREATED, ev22);
+               assertVertexInState(ExecutionState.CANCELED, ev31);
+               assertVertexInState(ExecutionState.CANCELED, ev32);
+               assertVertexInState(ExecutionState.CANCELED, ev41);
+               assertVertexInState(ExecutionState.CANCELED, ev42);
+               testMainThreadUtil.execute(() -> 
ev21.getCurrentExecutionAttempt().completeCancelling());
+
+               // 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);
+               assertVertexInState(ExecutionState.CREATED, ev31);
+               assertVertexInState(ExecutionState.CREATED, ev32);
+               assertVertexInState(ExecutionState.CREATED, ev41);
+               assertVertexInState(ExecutionState.CREATED, ev42);
+
+               // verify attempt number
+               assertEquals(1, 
ev11.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev12.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(1, 
ev21.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev22.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(1, 
ev31.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(1, 
ev32.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(1, 
ev41.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(1, 
ev42.getCurrentExecutionAttempt().getAttemptNumber());
+       }
+
+       /**
+        * Tests for scenes that a task fails for data consumption error, in 
which case the
+        * region containing the failed task, the region containing the 
unavailable result partition
+        * and all their consumer regions should be restarted.
+        * <pre>
+        *     (v11) --> (v21) -+-> (v31) --> (v41)
+        *                      x
+        *     (v12) --> (v22) -+-> (v32) --> (v42)
+        *
+        *                      ^
+        *                      |
+        *                  (blocking)
+        * </pre>
+        * 4 regions. Each region has 2 pipelined connected vertices.
+        */
+       @Test
+       public void testRegionFailoverForDataConsumptionErrorsInLazyMode() 
throws Exception {
+
+               // create a batch job graph with LAZY_FROM_SOURCES schedule mode
+               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();
+               final ExecutionVertex ev31 = vertexIterator.next();
+               final ExecutionVertex ev32 = vertexIterator.next();
+               final ExecutionVertex ev41 = vertexIterator.next();
+               final ExecutionVertex ev42 = vertexIterator.next();
+
+               // trigger ev21, ev22 scheduling on data from ev31 consumable
+               testMainThreadUtil.execute(() -> {
+                       eg.scheduleOrUpdateConsumers(new ResultPartitionID(
+                               
ev11.getProducedPartitions().keySet().iterator().next(),
+                               
ev11.getCurrentExecutionAttempt().getAttemptId()));
+                       eg.scheduleOrUpdateConsumers(new ResultPartitionID(
+                               
ev12.getProducedPartitions().keySet().iterator().next(),
+                               
ev12.getCurrentExecutionAttempt().getAttemptId()));
+
+                       // finish upstream regions to trigger scheduling of 
downstream regions
+                       ev11.getCurrentExecutionAttempt().markFinished();
+                       ev12.getCurrentExecutionAttempt().markFinished();
+                       ev21.getCurrentExecutionAttempt().markFinished();
+                       ev22.getCurrentExecutionAttempt().markFinished();
+
+                       // trigger ev41 scheduling on data from ev31 consumable
+                       eg.scheduleOrUpdateConsumers(new ResultPartitionID(
+                               
ev31.getProducedPartitions().keySet().iterator().next(),
+                               
ev31.getCurrentExecutionAttempt().getAttemptId()));
+               });
+
+               // verify initial state
+               assertVertexInState(ExecutionState.FINISHED, ev11);
+               assertVertexInState(ExecutionState.FINISHED, ev12);
+               assertVertexInState(ExecutionState.FINISHED, ev21);
+               assertVertexInState(ExecutionState.FINISHED, ev22);
+               assertVertexInState(ExecutionState.DEPLOYING, ev31);
+               assertVertexInState(ExecutionState.DEPLOYING, ev32);
+               assertVertexInState(ExecutionState.DEPLOYING, ev41);
+               assertVertexInState(ExecutionState.CREATED, ev42);
+
+               // verify initial attempt number
+               assertEquals(0, 
ev11.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev12.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev21.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev22.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev31.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev32.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev41.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev42.getCurrentExecutionAttempt().getAttemptNumber());
+
+               // trigger task failure of ev31 on consuming data from ev21
+               // vertices { ev11, ev21, ev31, ev32, ev41, ev42} should be 
affected
+               testMainThreadUtil.execute(() -> 
ev31.getCurrentExecutionAttempt().fail(new PartitionConnectionException(
+                       new ResultPartitionID(
+                               
ev21.getProducedPartitions().keySet().iterator().next(),
+                               
ev21.getCurrentExecutionAttempt().getAttemptId()),
+                       new Exception("Test failure"))));
+
+               // verify vertex states and complete cancellation
+               assertVertexInState(ExecutionState.FINISHED, ev11);
+               assertVertexInState(ExecutionState.FINISHED, ev12);
+               assertVertexInState(ExecutionState.FINISHED, ev21);
+               assertVertexInState(ExecutionState.FINISHED, ev22);
+               assertVertexInState(ExecutionState.FAILED, ev31);
+               assertVertexInState(ExecutionState.CANCELING, ev32);
+               assertVertexInState(ExecutionState.CANCELING, ev41);
+               assertVertexInState(ExecutionState.CANCELED, ev42);
+               testMainThreadUtil.execute(() -> {
+                       ev32.getCurrentExecutionAttempt().completeCancelling();
+                       ev41.getCurrentExecutionAttempt().completeCancelling();
+               });
+
+               // verify vertex states
+               // only vertices with consumable inputs can be scheduled
+               assertVertexInState(ExecutionState.DEPLOYING, ev11);
+               assertVertexInState(ExecutionState.FINISHED, ev12);
+               assertVertexInState(ExecutionState.CREATED, ev21);
+               assertVertexInState(ExecutionState.FINISHED, ev22);
+               assertVertexInState(ExecutionState.CREATED, ev31);
+               assertVertexInState(ExecutionState.CREATED, ev32);
+               assertVertexInState(ExecutionState.CREATED, ev41);
+               assertVertexInState(ExecutionState.CREATED, ev42);
+
+               // verify attempt number
+               assertEquals(1, 
ev11.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev12.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(1, 
ev21.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(0, 
ev22.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(1, 
ev31.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(1, 
ev32.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(1, 
ev41.getCurrentExecutionAttempt().getAttemptNumber());
+               assertEquals(1, 
ev42.getCurrentExecutionAttempt().getAttemptNumber());
+       }
+
+       /**
+        * Tests that checkpointing is working correctly in region failover.
+        */
+       @Test
+       public void testCheckpointingInRegionFailover() throws Exception {
+
+               final JobGraph jobGraph = createStreamingJobGraph();
+               final long checkpointId = 42L;
+               final ExecutionGraph eg = createExecutionGraph(jobGraph, 
checkpointId);
+
+               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();
+
+               assertNotNull(eg.getCheckpointCoordinator());
+               
assertFalse(eg.getCheckpointCoordinator().getPendingCheckpoints().isEmpty());
+
+               testMainThreadUtil.execute(() -> acknowledgeAllCheckpoints(
+                       checkpointId, eg.getCheckpointCoordinator(), 
eg.getAllExecutionVertices().iterator()));
+
+               // verify checkpoint has been completed successfully.
+               assertEquals(1, 
eg.getCheckpointCoordinator().getCheckpointStore().getNumberOfRetainedCheckpoints());
+               assertEquals(checkpointId, 
eg.getCheckpointCoordinator().getCheckpointStore().getLatestCheckpoint(false).getCheckpointID());
+
+               testMainThreadUtil.execute(() 
->ev11.getCurrentExecutionAttempt().fail(new Exception("Test Exception")));
+
+               // ensure vertex state and complete cancellation
+               assertVertexInState(ExecutionState.FAILED, ev11);
+               assertVertexInState(ExecutionState.DEPLOYING, ev12);
+               assertVertexInState(ExecutionState.CANCELING, ev21);
+               assertVertexInState(ExecutionState.DEPLOYING, ev22);
+               testMainThreadUtil.execute(() 
->ev21.getCurrentExecutionAttempt().completeCancelling());
+
+               verifyCheckpointRestoredAsExpected(checkpointId, eg);
+       }
+
+       /**
+        * Tests that the vertex partition state is reset property during 
failover.
+        */
+       @Test
+       public void testStatusResettingOnRegionFailover() throws Exception {
 
 Review comment:
   Is this test only to validate that `resetForNewExecution()` is called on the 
`ExecutionVertex`? 

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