redsanket commented on a change in pull request #28412: URL: https://github.com/apache/spark/pull/28412#discussion_r436151953
########## File path: common/kvstore/src/main/java/org/apache/spark/util/kvstore/HybridStore.java ########## @@ -0,0 +1,239 @@ +/* + * 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.spark.util.kvstore; + +import org.apache.spark.annotation.Private; + +import java.io.IOException; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.Collection; + +/** + * Implementation of KVStore that writes data to InMemoryStore at first and uses + * a background thread to dump data to LevelDB once the writing to InMemoryStore + * is completed. + */ +@Private +public class HybridStore implements KVStore { + + private InMemoryStore inMemoryStore = new InMemoryStore(); + private LevelDB levelDB = null; + + // Flag to indicate if we should use inMemoryStore Or levelDB. + private AtomicBoolean shouldUseInMemoryStore = new AtomicBoolean(true); + + // A background thread that dumps data in inMemoryStore to levelDB + private Thread backgroundThread = null; + + // A hash map that stores all class types (except CachedQuantile) that had been writen + // to inMemoryStore. + private ConcurrentHashMap<Class<?>, Boolean> klassMap = new ConcurrentHashMap<>(); + + // CachedQuantile can be written to kvstore after rebuildAppStore(), so we need + // to handle it specially to avoid conflicts. We will use a queue store CachedQuantile + // objects when the underlying store is inMemoryStore, and dump these objects to levelDB + // before the switch completes. + private Class<?> cachedQuantileKlass = null; + private ConcurrentLinkedQueue<Object> cachedQuantileQueue = new ConcurrentLinkedQueue<>(); Review comment: Why do we need to handle cachedQuantileQueue specially? ---------------------------------------------------------------- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
