LuciferYang commented on code in PR #44173:
URL: https://github.com/apache/spark/pull/44173#discussion_r1414916176


##########
core/src/main/scala/org/apache/spark/deploy/master/RecoveryModeFactory.scala:
##########
@@ -67,6 +67,25 @@ private[master] class FileSystemRecoveryModeFactory(conf: 
SparkConf, serializer:
   }
 }
 
+/**
+ * LeaderAgent in this case is a no-op. Since leader is forever leader as the 
actual
+ * recovery is made by restoring from RocksDB.
+ */
+private[master] class RocksDBRecoveryModeFactory(conf: SparkConf, serializer: 
Serializer)
+  extends StandaloneRecoveryModeFactory(conf, serializer) with Logging {
+
+  val recoveryDir = conf.get(RECOVERY_DIRECTORY)

Review Comment:
   Although this may be to maintain consistency with the style of 
`FileSystemRecoveryModeFactory`, it may be more suitable as a local variable 
within the `createPersistenceEngine()` method.



##########
core/src/main/scala/org/apache/spark/deploy/master/RocksDBPersistenceEngine.scala:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.deploy.master
+
+import java.nio.ByteBuffer
+import java.nio.charset.StandardCharsets.UTF_8
+import java.nio.file.{Files, Paths}
+
+import scala.collection.mutable.ArrayBuffer
+import scala.reflect.ClassTag
+
+import org.rocksdb._
+
+import org.apache.spark.internal.Logging
+import org.apache.spark.serializer.Serializer
+
+
+/**
+ * Stores data in RocksDB.
+ *
+ * @param dir Directory to setup RocksDB. Created if non-existent.
+ * @param serializer Used to serialize our objects.
+ */
+private[master] class RocksDBPersistenceEngine(
+    val dir: String,
+    val serializer: Serializer)
+  extends PersistenceEngine with Logging {
+
+  RocksDB.loadLibrary()
+
+  val path = Files.createDirectories(Paths.get(dir))
+
+  /**
+   * Use full filter.
+   * Disable compression in index data.
+   *
+   * 
https://github.com/facebook/rocksdb/wiki/RocksDB-Bloom-Filter#full-filters-new-format
+   */
+  private val tableFormatConfig = new BlockBasedTableConfig()
+    .setFilterPolicy(new BloomFilter(10.0D, false))
+    .setEnableIndexCompression(false)
+    .setIndexBlockRestartInterval(8)
+    .setFormatVersion(5)
+
+  /**
+   * Use ZSTD at the bottom most level to reduce the disk space
+   * Use LZ4 at the other levels because it's better than Snappy in general.
+   *
+   * https://github.com/facebook/rocksdb/wiki/Compression#configuration
+   */
+  private val options = new Options()
+    .setCreateIfMissing(true)
+    .setBottommostCompressionType(CompressionType.ZSTD_COMPRESSION)
+    .setCompressionType(CompressionType.LZ4_COMPRESSION)
+    .setTableFormatConfig(tableFormatConfig)
+
+  private val db: RocksDB = RocksDB.open(options, path.toString)
+
+  override def persist(name: String, obj: Object): Unit = {
+    val serialized = serializer.newInstance().serialize(obj)
+    val bytes = new Array[Byte](serialized.remaining())
+    serialized.get(bytes)
+    db.put(name.getBytes(UTF_8), bytes)
+  }
+
+  override def unpersist(name: String): Unit = {
+    db.delete(name.getBytes(UTF_8))
+  }
+
+  override def read[T: ClassTag](name: String): Seq[T] = {
+    val result = new ArrayBuffer[T]
+    val iter = db.newIterator()
+    iter.seek(name.getBytes(UTF_8))
+    while (iter.isValid && new String(iter.key()).startsWith(name)) {
+      
result.append(serializer.newInstance().deserialize[T](ByteBuffer.wrap(iter.value())))
+      iter.next()
+    }
+    iter.close()

Review Comment:
   should we close iter in finally block?



##########
core/src/main/scala/org/apache/spark/deploy/master/RocksDBPersistenceEngine.scala:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.deploy.master
+
+import java.nio.ByteBuffer
+import java.nio.charset.StandardCharsets.UTF_8
+import java.nio.file.{Files, Paths}
+
+import scala.collection.mutable.ArrayBuffer
+import scala.reflect.ClassTag
+
+import org.rocksdb._
+
+import org.apache.spark.internal.Logging
+import org.apache.spark.serializer.Serializer
+
+
+/**
+ * Stores data in RocksDB.
+ *
+ * @param dir Directory to setup RocksDB. Created if non-existent.
+ * @param serializer Used to serialize our objects.
+ */
+private[master] class RocksDBPersistenceEngine(
+    val dir: String,
+    val serializer: Serializer)
+  extends PersistenceEngine with Logging {
+
+  RocksDB.loadLibrary()
+
+  val path = Files.createDirectories(Paths.get(dir))

Review Comment:
   ```suggestion
     val path: Path = Files.createDirectories(Paths.get(dir))
   ```



##########
core/src/main/scala/org/apache/spark/deploy/master/RocksDBPersistenceEngine.scala:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.deploy.master
+
+import java.nio.ByteBuffer
+import java.nio.charset.StandardCharsets.UTF_8
+import java.nio.file.{Files, Paths}
+
+import scala.collection.mutable.ArrayBuffer
+import scala.reflect.ClassTag
+
+import org.rocksdb._
+
+import org.apache.spark.internal.Logging
+import org.apache.spark.serializer.Serializer
+
+
+/**
+ * Stores data in RocksDB.
+ *
+ * @param dir Directory to setup RocksDB. Created if non-existent.
+ * @param serializer Used to serialize our objects.
+ */
+private[master] class RocksDBPersistenceEngine(
+    val dir: String,
+    val serializer: Serializer)
+  extends PersistenceEngine with Logging {
+
+  RocksDB.loadLibrary()
+
+  val path = Files.createDirectories(Paths.get(dir))
+
+  /**
+   * Use full filter.
+   * Disable compression in index data.
+   *
+   * 
https://github.com/facebook/rocksdb/wiki/RocksDB-Bloom-Filter#full-filters-new-format
+   */
+  private val tableFormatConfig = new BlockBasedTableConfig()
+    .setFilterPolicy(new BloomFilter(10.0D, false))
+    .setEnableIndexCompression(false)
+    .setIndexBlockRestartInterval(8)
+    .setFormatVersion(5)
+
+  /**
+   * Use ZSTD at the bottom most level to reduce the disk space
+   * Use LZ4 at the other levels because it's better than Snappy in general.
+   *
+   * https://github.com/facebook/rocksdb/wiki/Compression#configuration
+   */
+  private val options = new Options()
+    .setCreateIfMissing(true)
+    .setBottommostCompressionType(CompressionType.ZSTD_COMPRESSION)
+    .setCompressionType(CompressionType.LZ4_COMPRESSION)
+    .setTableFormatConfig(tableFormatConfig)
+
+  private val db: RocksDB = RocksDB.open(options, path.toString)
+
+  override def persist(name: String, obj: Object): Unit = {
+    val serialized = serializer.newInstance().serialize(obj)

Review Comment:
   Can `db.put(name.getBytes(UTF_8), serialized.array())` be executed directly 
when ` serialized.hasArray` is true? Is this a feasible optimization?
   
   
   
   



##########
core/src/main/scala/org/apache/spark/deploy/master/RocksDBPersistenceEngine.scala:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.deploy.master
+
+import java.nio.ByteBuffer
+import java.nio.charset.StandardCharsets.UTF_8
+import java.nio.file.{Files, Paths}
+
+import scala.collection.mutable.ArrayBuffer
+import scala.reflect.ClassTag
+
+import org.rocksdb._
+
+import org.apache.spark.internal.Logging
+import org.apache.spark.serializer.Serializer
+
+
+/**
+ * Stores data in RocksDB.
+ *
+ * @param dir Directory to setup RocksDB. Created if non-existent.
+ * @param serializer Used to serialize our objects.
+ */
+private[master] class RocksDBPersistenceEngine(
+    val dir: String,
+    val serializer: Serializer)
+  extends PersistenceEngine with Logging {
+
+  RocksDB.loadLibrary()
+
+  val path = Files.createDirectories(Paths.get(dir))

Review Comment:
   due to this a `public` member



-- 
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-unsubscr...@spark.apache.org

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