1996fanrui commented on code in PR #741: URL: https://github.com/apache/flink-kubernetes-operator/pull/741#discussion_r1448941925
########## 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: Yeah, I refer to `ConfigMapView` during developing. I didn't share logic due to some reasons: 1. The View and State are different - `ConfigMapView` stores `ConfigMap` for each job, so we create it directly. - `JobStateView` stores state for each stateType, it means that part of state types of current job are stored in the database, but the rest of the state types may have been created in the database. - That's why `JobStateView` have `NOT_NEEDED` and `NEEDS_DELETE`, but `ConfigMapView` doesn't. 2. Based on the first reason, the `ConfigMapView` accesses the whole ConfigMap, `JobStateView` accesses each row of database. It's hard to share code. -- 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]
