1996fanrui commented on code in PR #741:
URL: 
https://github.com/apache/flink-kubernetes-operator/pull/741#discussion_r1449726286


##########
flink-autoscaler-plugin-jdbc/src/main/java/org/apache/flink/autoscaler/jdbc/state/JobStateView.java:
##########
@@ -0,0 +1,262 @@
+/*
+ * 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.autoscaler.jdbc.state;
+
+import org.apache.flink.annotation.VisibleForTesting;
+
+import javax.annotation.Nonnull;
+import javax.annotation.concurrent.NotThreadSafe;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+
+import static 
org.apache.flink.autoscaler.jdbc.state.JobStateView.State.NEEDS_CREATE;
+import static 
org.apache.flink.autoscaler.jdbc.state.JobStateView.State.NEEDS_DELETE;
+import static 
org.apache.flink.autoscaler.jdbc.state.JobStateView.State.NEEDS_UPDATE;
+import static 
org.apache.flink.autoscaler.jdbc.state.JobStateView.State.NOT_NEEDED;
+import static 
org.apache.flink.autoscaler.jdbc.state.JobStateView.State.UP_TO_DATE;
+import static org.apache.flink.util.Preconditions.checkState;
+
+/** The view of job state. */
+@NotThreadSafe
+public class JobStateView {
+
+    /**
+     * The state of state type about the cache and database.
+     *
+     * <p>Note: {@link #inLocally} and {@link #inDatabase} are only for 
understand, we don't use
+     * them.
+     */
+    @SuppressWarnings("unused")
+    enum State {
+
+        /** State doesn't exist at database, and it's not used so far, so it's 
not needed. */
+        NOT_NEEDED(false, false, false),
+        /** State is only stored locally, not created in JDBC database yet. */
+        NEEDS_CREATE(true, false, true),
+        /** State exists in JDBC database but there are newer local changes. */
+        NEEDS_UPDATE(true, true, true),
+        /** State is stored locally and in database, and they are same. */
+        UP_TO_DATE(true, true, false),
+        /** State is stored in database, but it's deleted in local. */
+        NEEDS_DELETE(false, true, true);

Review Comment:
   > It would be good to move more of the logic into the core, to avoid 
duplicating / writing similar logic. 
   
   Sounds make sense, after I analyze, some of logic are same, such as: 
   
   - `ConfigMapStore` and `JDBCStore` can be abstracted to `StringStateStore` 
interface
     - They support `put`, `get` and `remove`
     - The parameters of `ConfigMapStore` are the (JobContext, String key, 
String value).
     - The parameters of `JDBCStore` are the (String jobKey, StateType 
stateType, String value).
     - We can define a interface `StringStateStore`, and the parameters are 
`(JobContext, StateType stateType, String value)`.
   
   - `KubernetesAutoScalerStateStore` and `JDBCAutoScalerStateStore` can be 
abstracted to `AbstractAutoscalerStateStore`
     - They support serialize and compress `Original State` to String.
     - `AbstractAutoscalerStateStore` can reuse the serialize and compress logic
     - `KubernetesAutoScalerStateStore` support the limitation of stateValue
     - We can define a parameter for `AbstractAutoscalerStateStore`, the 
limitation is disabled by default, and `KubernetesAutoScalerStateStore` can 
enable it.
   
   And I created FLINK-34065 to follow it.



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