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/08/09 05:31:17 UTC

[GitHub] [spark] mridulm commented on a diff in pull request #36200: [SPARK-38909][CORE][YARN] Encapsulate `LevelDB` used to store remote/external shuffle state as `DB`

mridulm commented on code in PR #36200:
URL: https://github.com/apache/spark/pull/36200#discussion_r940910008


##########
common/network-common/src/main/java/org/apache/spark/network/util/DBProvider.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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 com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.annotations.VisibleForTesting;
+
+import org.apache.spark.network.shuffledb.DBBackend;
+import org.apache.spark.network.shuffledb.LevelDB;
+import org.apache.spark.network.shuffledb.DB;
+import org.apache.spark.network.shuffledb.StoreVersion;
+
+public class DBProvider {
+    public static DB initDB(
+        DBBackend dbBackend,
+        File dbFile,
+        StoreVersion version,
+        ObjectMapper mapper) throws IOException {
+      if (dbFile != null) {
+        // TODO: SPARK-38888, add rocksdb implementation.
+        switch (dbBackend) {
+          case LEVELDB:
+            org.iq80.leveldb.DB levelDB = LevelDBProvider.initLevelDB(dbFile, version, mapper);
+            return levelDB != null ? new LevelDB(levelDB) : null;
+          default:
+            return null;
+        }
+      }
+      return null;
+    }
+
+    @VisibleForTesting
+    public static DB initDB(DBBackend dbBackend, File file) throws IOException {
+      if (file != null) {
+        // TODO: SPARK-38888, add rocksdb implementation.
+        switch (dbBackend) {
+          case LEVELDB: return new LevelDB(LevelDBProvider.initLevelDB(file));
+        default: return null;

Review Comment:
   Discuss: Should we throw exception instead ?



##########
common/network-yarn/src/main/java/org/apache/spark/network/yarn/YarnShuffleService.java:
##########
@@ -331,13 +344,13 @@ static MergedShuffleFileManager newMergedShuffleFileManagerInstance(
   }
 
   private void loadSecretsFromDb() throws IOException {
-    secretsFile = initRecoveryDb(SECRETS_RECOVERY_FILE_NAME);
+    secretsFile = initRecoveryDb(SECRETS_RECOVERY_FILE_NAME + dbBackend.suffix());

Review Comment:
   minor nit: perhaps we can add `dbBackend.fileName(prefix: String)` or some such instead  (and remove suffix as well) ?



##########
common/network-common/src/main/java/org/apache/spark/network/shuffledb/LevelDBIterator.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * 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.shuffledb;
+
+import com.google.common.base.Throwables;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+public class LevelDBIterator implements DBIterator {
+
+    private final org.iq80.leveldb.DBIterator it;
+
+    private boolean checkedNext;
+
+    private boolean closed;
+
+    private Map.Entry<byte[], byte[]> next;
+
+    public LevelDBIterator(org.iq80.leveldb.DBIterator it) {
+        this.it = it;
+    }
+
+    @Override
+    public boolean hasNext() {
+      if (!checkedNext && !closed) {
+        next = loadNext();
+        checkedNext = true;
+      }
+      if (!closed && next == null) {
+        try {
+          close();
+        } catch (IOException ioe) {
+          throw Throwables.propagate(ioe);
+        }
+      }
+      return next != null;
+    }
+
+    @Override
+    public Map.Entry<byte[], byte[]> next() {
+        if (!hasNext()) {
+          throw new NoSuchElementException();
+        }
+        checkedNext = false;
+        Map.Entry<byte[], byte[]> ret = next;
+        next = null;
+        return ret;
+    }
+
+    @Override
+    public void close() throws IOException {
+      if (!closed) {
+       it.close();
+       closed = true;
+      }

Review Comment:
   set `next` to `null` (for ex, `hasNext`, `close`, `hasNext` -> `true`, should be `false`)



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