HeartSaVioR commented on a change in pull request #28412:
URL: https://github.com/apache/spark/pull/28412#discussion_r436235957



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

Review comment:
       Given we still have to deal with exception, how about generalizing a bit 
more, like allowing to write on in-memory DB but capturing all of the write 
operations between the time the replay is done and the time we just shift to 
level DB?
   
   You may feel it sounds as back and forth - sorry I didn't realize there are 
additional writes after replaying. But it only applies to the case during 
migrating so would be still simpler than before, and we can get rid of 
assertion on being "read-only" with exception.
   
   I'm also OK with current state - eventually I'll try to deal with that 
afterwards.




----------------------------------------------------------------
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:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to