yunfengzhou-hub commented on a change in pull request #17:
URL: https://github.com/apache/flink-ml/pull/17#discussion_r726039828



##########
File path: 
flink-ml-iteration/src/main/java/org/apache/flink/ml/iteration/operator/HeadOperator.java
##########
@@ -129,12 +168,89 @@ public void setup(
     public void initializeState(StateInitializationContext context) throws 
Exception {
         super.initializeState(context);
 
+        parallelismState =
+                context.getOperatorStateStore()
+                        .getUnionListState(
+                                new ListStateDescriptor<>("parallelism", 
IntSerializer.INSTANCE));
+        OperatorStateUtils.getUniqueElement(parallelismState, "parallelism")
+                .ifPresent(
+                        oldParallelism ->
+                                checkState(
+                                        oldParallelism
+                                                == getRuntimeContext()
+                                                        
.getNumberOfParallelSubtasks(),
+                                        "The head operator is recovered with 
parallelism changed from "
+                                                + oldParallelism
+                                                + " to "
+                                                + getRuntimeContext()
+                                                        
.getNumberOfParallelSubtasks()));
+
+        // Initialize the status and the record processor.
         processorContext = new ContextImpl();
-        status = HeadOperatorStatus.RUNNING;
-        recordProcessor = new 
RegularHeadOperatorRecordProcessor(processorContext);
+        statusState =
+                context.getOperatorStateStore()
+                        .getListState(new ListStateDescriptor<>("status", 
Integer.class));
+        status =
+                HeadOperatorStatus.values()[
+                        OperatorStateUtils.getUniqueElement(statusState, 
"status").orElse(0)];
+        if (status == HeadOperatorStatus.RUNNING) {
+            recordProcessor = new 
RegularHeadOperatorRecordProcessor(processorContext);
+        } else {
+            recordProcessor = new TerminatingHeadOperatorRecordProcessor();

Review comment:
       In which case would a `HeadOperator` be terminated when it has not 
finished initialization?




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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to