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


##########
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:
   Hi @mxm @gyfora , in the beginning of design the JDBC state store, we use 
the state type id in the database table.
   
   After I thinking more and this suggestion from @mxm . It's better to share 
some code between `KubernetesAutoScalerStateStore` and 
`JDBCAutoScalerStateStore`. So I change the state type from id to `identifier` 
(From int to String).
   
   Align it to `KubernetesAutoScalerStateStore`, using: `scalingHistory`, 
`scalingTracking`, `collectedMetrics` and `parallelismOverrides`. It has 2 
advantages : 
   
   - It's easy to share the `StateType` class
   - When we use the `JDBCAutoScalerStateStore`, the identifier is easier to 
troubleshooting than id. For example, we needs to query  some states  from 
database manually. It's easy to understand.
   
   We can ensure the `identifier` length isn't too long, it won't introduce too 
many storage cost.
   
   I have update it in the latest hotfix commit, WDYT?



-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to