rmetzger commented on a change in pull request #14879:
URL: https://github.com/apache/flink/pull/14879#discussion_r570875547



##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/declarative/Restarting.java
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.declarative;
+
+import org.apache.flink.api.common.JobStatus;
+import org.apache.flink.runtime.executiongraph.ArchivedExecutionGraph;
+import org.apache.flink.runtime.executiongraph.ExecutionGraph;
+import org.apache.flink.runtime.executiongraph.TaskExecutionStateTransition;
+import org.apache.flink.runtime.scheduler.ExecutionGraphHandler;
+import org.apache.flink.runtime.scheduler.OperatorCoordinatorHandler;
+
+import org.slf4j.Logger;
+
+import java.time.Duration;
+
+/** State which describes a job which is currently being restarted. */
+class Restarting extends StateWithExecutionGraph {
+
+    private final Context context;
+
+    private final Duration backoffTime;
+
+    Restarting(
+            Context context,
+            ExecutionGraph executionGraph,
+            ExecutionGraphHandler executionGraphHandler,
+            OperatorCoordinatorHandler operatorCoordinatorHandler,
+            Logger logger,
+            Duration backoffTime) {
+        super(context, executionGraph, executionGraphHandler, 
operatorCoordinatorHandler, logger);
+        this.context = context;
+        this.backoffTime = backoffTime;
+    }
+
+    @Override
+    public void onEnter() {
+        getExecutionGraph().cancel();
+    }
+
+    @Override
+    public JobStatus getJobStatus() {
+        return JobStatus.RESTARTING;
+    }
+
+    @Override
+    public void cancel() {
+        context.goToCanceling(
+                getExecutionGraph(), getExecutionGraphHandler(), 
getOperatorCoordinatorHandler());
+    }
+
+    @Override
+    public void handleGlobalFailure(Throwable cause) {
+        // don't do anything
+    }
+
+    @Override
+    boolean updateTaskExecutionState(TaskExecutionStateTransition 
taskExecutionStateTransition) {
+        return getExecutionGraph().updateState(taskExecutionStateTransition);
+    }
+
+    @Override
+    void onTerminalState(JobStatus terminalState) {
+        // TODO revisit this
+        switch (terminalState) {
+            case CANCELED:
+                context.runIfState(this, context::goToWaitingForResources, 
backoffTime);
+                break;
+            case SUSPENDED:
+                context.runIfState(
+                        this,
+                        () ->
+                                context.goToFinished(
+                                        
ArchivedExecutionGraph.createFrom(getExecutionGraph())),
+                        Duration.ZERO);
+                break;
+            default:
+                throw new IllegalArgumentException("Unexpected terminal state 
" + terminalState);

Review comment:
       This is also a diff by me compared to the POC code. The problem is that 
`StateWithExecutionGraph.suspend` used to do a suspend on the execution graph 
(which triggered this method through the termination future) and a transition 
to suspend (This leads to two state transitions in case of Executing, and an 
IllegalArgumentException for Restarting).
   
   Now,  the suspend method just calls ExecutionGraph.suspend() and we do the 
state transition in the termination future.




----------------------------------------------------------------
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:
[email protected]


Reply via email to