You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/09/02 09:13:22 UTC

[GitHub] [spark] Ngone51 commented on a diff in pull request #37610: [SPARK-38888][BUILD][CORE][YARN][DOCS] Add `RocksDB` support for shuffle state store

Ngone51 commented on code in PR #37610:
URL: https://github.com/apache/spark/pull/37610#discussion_r961468749


##########
common/network-common/src/main/java/org/apache/spark/network/util/RocksDBProvider.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.network.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Objects;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.annotations.VisibleForTesting;
+import org.rocksdb.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.spark.network.shuffledb.StoreVersion;
+
+/**
+ * RocksDB utility class available in the network package.
+ */
+public class RocksDBProvider {
+
+    static {
+      org.rocksdb.RocksDB.loadLibrary();
+    }
+
+    private static final Logger logger = LoggerFactory.getLogger(RocksDBProvider.class);
+
+    public static RocksDB initRockDB(File dbFile, StoreVersion version, ObjectMapper mapper) throws
+        IOException {
+      RocksDB tmpDb = null;
+      if (dbFile != null) {
+        BloomFilter fullFilter =
+          new BloomFilter(10.0D /* BloomFilter.DEFAULT_BITS_PER_KEY */, false);
+        BlockBasedTableConfig tableFormatConfig = new BlockBasedTableConfig()
+          .setFilterPolicy(fullFilter)
+          .setEnableIndexCompression(false)
+          .setIndexBlockRestartInterval(8)
+          .setFormatVersion(5);
+
+        Options dbOptions = new Options();
+        RocksDBLogger rocksDBLogger = new RocksDBLogger(dbOptions);
+
+        dbOptions.setCreateIfMissing(false);
+        dbOptions.setBottommostCompressionType(CompressionType.ZSTD_COMPRESSION);
+        dbOptions.setCompressionType(CompressionType.LZ4_COMPRESSION);
+        dbOptions.setTableFormatConfig(tableFormatConfig);
+        dbOptions.setLogger(rocksDBLogger);
+
+        try {
+          tmpDb = RocksDB.open(dbOptions, dbFile.toString());
+        } catch (RocksDBException e) {
+          if (e.getStatus().getCode() == Status.Code.NotFound) {
+            logger.info("Creating state database at " + dbFile);
+            dbOptions.setCreateIfMissing(true);
+            try {
+              tmpDb = RocksDB.open(dbOptions, dbFile.toString());
+            } catch (RocksDBException dbExc) {
+              throw new IOException("Unable to create state store", dbExc);
+            }
+          } else {
+            // the RocksDB file seems to be corrupt somehow.  Let's just blow it away and create
+            // a new one, so we can keep processing new apps
+            logger.error("error opening rocksdb file {}. Creating new file, will not be able to " +
+              "recover state for existing applications", dbFile, e);
+            if (dbFile.isDirectory()) {
+              for (File f : Objects.requireNonNull(dbFile.listFiles())) {

Review Comment:
   > I think it is safer to follow the old code flow, could LevelDBProvider and RocksDBProvider be fixed together after further investigation?
   
   sounds good.



-- 
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: reviews-unsubscribe@spark.apache.org

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


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