tzulitai commented on a change in pull request #8861: 
[FLINK-12963][state-processor-api] Add savepoint writer for bootstrapping new 
savepoints
URL: https://github.com/apache/flink/pull/8861#discussion_r298019548
 
 

 ##########
 File path: 
flink-libraries/flink-state-processing-api/src/main/java/org/apache/flink/state/api/WritableSavepoint.java
 ##########
 @@ -0,0 +1,129 @@
+/*
+ * 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.state.api;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.api.java.DataSet;
+import org.apache.flink.core.fs.Path;
+import org.apache.flink.runtime.checkpoint.OperatorState;
+import org.apache.flink.runtime.state.StateBackend;
+import org.apache.flink.state.api.output.OperatorStateReducer;
+import org.apache.flink.state.api.output.OperatorSubtaskStateReducer;
+import org.apache.flink.state.api.output.SavepointOutputFormat;
+import org.apache.flink.state.api.runtime.metadata.SavepointMetadata;
+
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Any savepoint that can be written to from a batch context.
+ * @param <F> The implementation type.
+ */
+@PublicEvolving
+@SuppressWarnings("WeakerAccess")
+public abstract class WritableSavepoint<F extends WritableSavepoint> {
+
+       protected final Map<String, BootstrapTransformation> transformations;
+
+       protected final List<String> droppedOperators;
+
+       WritableSavepoint() {
+               this.transformations  = new HashMap<>();
+               this.droppedOperators = new ArrayList<>();
+       }
+
+       /**
+        * Drop an existing operator from the savepoint.
+        * @param uid The uid of the operator.
+        * @return A modified savepoint.
+        */
+       @SuppressWarnings("unchecked")
+       public F removeOperator(String uid) {
+               droppedOperators.add(uid);
 
 Review comment:
   I'm quite confused about the interplay between these data structures and the 
`write(...)` implementation in `ExistingSavepoint`. It seems like some operator 
removal / addition work could have been done already when call sites call 
`removeOperator()` / `withOperator()`. Instead, from what I understand, we're 
only keeping track of what was added / removed in these data structures, and 
then lazily verifying the additions / removals on write in the subclasses, as 
well as figuring out what exactly is the final set of operators to write.
   
   Can't the base implementation of `removeOperator(String uid)` be:
   ```
   public final F removeOperator(String uid) {
       savepointMetaData.removeOperator(uid);
       return this;
   }
   ```
   
   and `withOperator(String uid, BootstrapTransformation<T> transformation)` be:
   ```
   public <T> final F withOperator(String uid, BootstrapTransformation<T> 
transformation) {
       if (savepointMetadata.containsOperator(uid)) {
           throw new IllegalArgumentException(...)
       }
   
       savepointMetadata.addOperator(uid, transformation);
   }
   ```
   
   this way we'll only be looking at the savepoint metadata as the single 
maintainer of what operator states currently exist. This seems to be much more 
readable / easy to maintain, IMO.
   The only work we would need to do in this case is that `SavepointMetadata` 
now don't bookkeep `OperatorState`s, but rather `Either<OperatorState, 
BootstrapTransformation>`.
   
   With this approach, the `finalOperatorStates` is automatically determined by 
the current state of the `SavepointMetadata` when writing the savepoint.
   
   What do you think?

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


With regards,
Apache Git Services

Reply via email to