wangyang0918 commented on a change in pull request #13864: URL: https://github.com/apache/flink/pull/13864#discussion_r517166908
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/jobmanager/DefaultJobGraphStore.java ########## @@ -0,0 +1,329 @@ +/* + * 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.runtime.jobmanager; + +import org.apache.flink.api.common.JobID; +import org.apache.flink.runtime.jobgraph.JobGraph; +import org.apache.flink.runtime.state.RetrievableStateHandle; +import org.apache.flink.runtime.statehandle.StateHandleStore; +import org.apache.flink.util.FlinkException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.Nullable; +import javax.annotation.concurrent.GuardedBy; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.function.Function; + +import static org.apache.flink.util.Preconditions.checkNotNull; +import static org.apache.flink.util.Preconditions.checkState; + +/** + * Default implementation for {@link JobGraphStore}. Combined with different {@link StateHandleStore}, we could persist + * the job graphs to various distributed storage. Also combined with different {@link JobGraphStoreWatcher}, we could + * get all the changes on the job graph store and do the response. + * + * <p>We have to make some variables {@link #lock}, {@link #addedJobGraphs}, and method {@link #verifyIsRunning()} + * as protected so that they could be used in the {@link ZooKeeperJobGraphStore}. + */ +public class DefaultJobGraphStore implements JobGraphStore, JobGraphStore.JobGraphListener { + + private static final Logger LOG = LoggerFactory.getLogger(DefaultJobGraphStore.class); + + /** Lock to synchronize with the {@link JobGraphListener}. */ + protected final Object lock = new Object(); + + /** The set of IDs of all added job graphs. */ + @GuardedBy("lock") + protected final Set<JobID> addedJobGraphs = new HashSet<>(); + + /** Submitted job graphs handle store. */ + private final StateHandleStore<JobGraph> jobGraphStateHandleStore; + + private final JobGraphStoreWatcher jobGraphStoreWatcher; + + /** The job graph store description. Usually it is the storage name + * (e.g. ZooKeeper path or Kubernetes ConfigMap name). */ + private final String jobGraphStoreDescription; + + private final Function<String, JobID> nameToJobIDConverter; + + private final Function<JobID, String> jobIDToNameConverter; + + /** The external listener to be notified on races. */ + @GuardedBy("lock") + private JobGraphListener jobGraphListener; + + /** Flag indicating whether this instance is running. */ + @GuardedBy("lock") + private volatile boolean running; + + public DefaultJobGraphStore( + StateHandleStore<JobGraph> stateHandleStore, + JobGraphStoreWatcher jobGraphStoreWatcher, + String jobGraphStoreDescription, + Function<String, JobID> nameToJobIDConverter, + Function<JobID, String> jobIDToNameConverter) { Review comment: Nice suggestion. I will add a new interface `JobGraphStoreUtil`. ---------------------------------------------------------------- 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]
