[GitHub] [spark] xuanyuanking commented on a change in pull request #32272: [SPARK-35172][SS] The implementation of RocksDBCheckpointMetadata

2021-05-27 Thread GitBox


xuanyuanking commented on a change in pull request #32272:
URL: https://github.com/apache/spark/pull/32272#discussion_r641196335



##
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDBFileManager.scala
##
@@ -0,0 +1,165 @@
+/*
+ * 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.sql.execution.streaming.state
+
+import java.io.File
+import java.nio.charset.StandardCharsets.UTF_8
+import java.nio.file.Files
+
+import scala.collection.Seq
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include
+import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
+import com.fasterxml.jackson.module.scala.{DefaultScalaModule, 
ScalaObjectMapper}
+import org.json4s.NoTypeHints
+import org.json4s.jackson.Serialization
+
+/**
+ * Classes to represent metadata of checkpoints saved to DFS. Since this is 
converted to JSON, any
+ * changes to this MUST be backward-compatible.
+ */
+case class RocksDBCheckpointMetadata(
+sstFiles: Seq[RocksDBSstFile],
+logFiles: Seq[RocksDBLogFile],
+numKeys: Long) {
+  import RocksDBCheckpointMetadata._
+
+  def json: String = {
+// We turn this field into a null to avoid write a empty logFiles field in 
the json.
+val nullified = if (logFiles.isEmpty) this.copy(logFiles = null) else this
+mapper.writeValueAsString(nullified)
+  }
+
+  def prettyJson: String = 
Serialization.writePretty(this)(RocksDBCheckpointMetadata.format)
+
+  def writeToFile(metadataFile: File): Unit = {
+val writer = Files.newBufferedWriter(metadataFile.toPath, UTF_8)
+try {
+  writer.write(s"v$VERSION\n")
+  writer.write(this.json)
+} finally {
+  writer.close()
+}
+  }
+
+  def immutableFiles: Seq[RocksDBImmutableFile] = sstFiles ++ logFiles
+}
+
+/** Helper class for [[RocksDBCheckpointMetadata]] */
+object RocksDBCheckpointMetadata {
+  val VERSION = 1
+
+  implicit val format = Serialization.formats(NoTypeHints)
+
+  /** Used to convert between classes and JSON. */
+  lazy val mapper = {
+val _mapper = new ObjectMapper with ScalaObjectMapper
+_mapper.setSerializationInclusion(Include.NON_ABSENT)
+_mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
+_mapper.registerModule(DefaultScalaModule)
+_mapper
+  }
+
+  def readFromFile(metadataFile: File): RocksDBCheckpointMetadata = {
+val reader = Files.newBufferedReader(metadataFile.toPath, UTF_8)
+try {
+  val versionLine = reader.readLine()
+  if (versionLine != s"v$VERSION") {
+throw new IllegalStateException(
+  s"Cannot read RocksDB checkpoint metadata of version $versionLine")
+  }
+  Serialization.read[RocksDBCheckpointMetadata](reader)
+} finally {
+  reader.close()
+}
+  }
+
+  def apply(rocksDBFiles: Seq[RocksDBImmutableFile], numKeys: Long): 
RocksDBCheckpointMetadata = {
+val sstFiles = rocksDBFiles.collect { case file: RocksDBSstFile => file }
+val logFiles = rocksDBFiles.collect { case file: RocksDBLogFile => file }
+
+RocksDBCheckpointMetadata(sstFiles, logFiles, numKeys)
+  }
+}
+
+/**
+ * A RocksDBImmutableFile maintains a mapping between a local RocksDB file 
name and the name of
+ * its copy on DFS. Since these files are immutable, their DFS copies can be 
reused.
+ */
+sealed trait RocksDBImmutableFile {
+  def localFileName: String
+  def dfsFileName: String
+  def sizeBytes: Long
+
+  /**
+   * Whether another local file is same as the file described by this class.
+   * A file is same only when the name and the size are same.
+   */
+  def isSameFile(otherFile: File): Boolean = {
+otherFile.getName == localFileName && otherFile.length() == sizeBytes
+  }
+}
+
+/**
+ * Class to represent a RocksDB SST file. Since this is converted to JSON,
+ * any changes to these MUST be backward-compatible.
+ */
+private[sql] case class RocksDBSstFile(
+localFileName: String,
+dfsSstFileName: String,
+sizeBytes: Long) extends RocksDBImmutableFile {
+
+  override def dfsFileName: String = dfsSstFileName
+}
+
+/**
+ * Class to represent a RocksDB Log file. Since this is converted to JSON,
+ * any changes to these MUST be 

[GitHub] [spark] xuanyuanking commented on a change in pull request #32272: [SPARK-35172][SS] The implementation of RocksDBCheckpointMetadata

2021-05-25 Thread GitBox


xuanyuanking commented on a change in pull request #32272:
URL: https://github.com/apache/spark/pull/32272#discussion_r638529708



##
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDBFileManager.scala
##
@@ -0,0 +1,165 @@
+/*
+ * 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.sql.execution.streaming.state
+
+import java.io.File
+import java.nio.charset.StandardCharsets.UTF_8
+import java.nio.file.Files
+
+import scala.collection.Seq
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include
+import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
+import com.fasterxml.jackson.module.scala.{DefaultScalaModule, 
ScalaObjectMapper}
+import org.json4s.NoTypeHints
+import org.json4s.jackson.Serialization
+
+/**
+ * Classes to represent metadata of checkpoints saved to DFS. Since this is 
converted to JSON, any
+ * changes to this MUST be backward-compatible.
+ */
+case class RocksDBCheckpointMetadata(
+sstFiles: Seq[RocksDBSstFile],
+logFiles: Seq[RocksDBLogFile],
+numKeys: Long) {
+  import RocksDBCheckpointMetadata._
+
+  def json: String = {
+// We turn this field into a null to avoid write a empty logFiles field in 
the json.
+val nullified = if (logFiles.isEmpty) this.copy(logFiles = null) else this
+mapper.writeValueAsString(nullified)
+  }
+
+  def prettyJson: String = 
Serialization.writePretty(this)(RocksDBCheckpointMetadata.format)
+
+  def writeToFile(metadataFile: File): Unit = {
+val writer = Files.newBufferedWriter(metadataFile.toPath, UTF_8)
+try {
+  writer.write(s"v$VERSION\n")
+  writer.write(this.json)
+} finally {
+  writer.close()
+}
+  }
+
+  def immutableFiles: Seq[RocksDBImmutableFile] = sstFiles ++ logFiles
+}
+
+/** Helper class for [[RocksDBCheckpointMetadata]] */
+object RocksDBCheckpointMetadata {
+  val VERSION = 1
+
+  implicit val format = Serialization.formats(NoTypeHints)
+
+  /** Used to convert between classes and JSON. */
+  lazy val mapper = {
+val _mapper = new ObjectMapper with ScalaObjectMapper
+_mapper.setSerializationInclusion(Include.NON_ABSENT)
+_mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
+_mapper.registerModule(DefaultScalaModule)
+_mapper
+  }
+
+  def readFromFile(metadataFile: File): RocksDBCheckpointMetadata = {
+val reader = Files.newBufferedReader(metadataFile.toPath, UTF_8)
+try {
+  val versionLine = reader.readLine()
+  if (versionLine != s"v$VERSION") {
+throw new IllegalStateException(
+  s"Cannot read RocksDB checkpoint metadata of version $versionLine")
+  }
+  Serialization.read[RocksDBCheckpointMetadata](reader)
+} finally {
+  reader.close()
+}
+  }
+
+  def apply(rocksDBFiles: Seq[RocksDBImmutableFile], numKeys: Long): 
RocksDBCheckpointMetadata = {
+val sstFiles = rocksDBFiles.collect { case file: RocksDBSstFile => file }
+val logFiles = rocksDBFiles.collect { case file: RocksDBLogFile => file }
+
+RocksDBCheckpointMetadata(sstFiles, logFiles, numKeys)
+  }
+}
+
+/**
+ * A RocksDBImmutableFile maintains a mapping between a local RocksDB file 
name and the name of
+ * its copy on DFS. Since these files are immutable, their DFS copies can be 
reused.
+ */
+sealed trait RocksDBImmutableFile {
+  def localFileName: String
+  def dfsFileName: String
+  def sizeBytes: Long
+
+  /**
+   * Whether another local file is same as the file described by this class.
+   * A file is same only when the name and the size are same.
+   */
+  def isSameFile(otherFile: File): Boolean = {
+otherFile.getName == localFileName && otherFile.length() == sizeBytes
+  }
+}
+
+/**
+ * Class to represent a RocksDB SST file. Since this is converted to JSON,
+ * any changes to these MUST be backward-compatible.
+ */
+private[sql] case class RocksDBSstFile(
+localFileName: String,
+dfsSstFileName: String,
+sizeBytes: Long) extends RocksDBImmutableFile {
+
+  override def dfsFileName: String = dfsSstFileName
+}
+
+/**
+ * Class to represent a RocksDB Log file. Since this is converted to JSON,
+ * any changes to these MUST be 

[GitHub] [spark] xuanyuanking commented on a change in pull request #32272: [SPARK-35172][SS] The implementation of RocksDBCheckpointMetadata

2021-05-25 Thread GitBox


xuanyuanking commented on a change in pull request #32272:
URL: https://github.com/apache/spark/pull/32272#discussion_r638519692



##
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDBFileManager.scala
##
@@ -0,0 +1,165 @@
+/*
+ * 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.sql.execution.streaming.state
+
+import java.io.File
+import java.nio.charset.StandardCharsets.UTF_8
+import java.nio.file.Files
+
+import scala.collection.Seq
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include
+import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
+import com.fasterxml.jackson.module.scala.{DefaultScalaModule, 
ScalaObjectMapper}
+import org.json4s.NoTypeHints
+import org.json4s.jackson.Serialization
+
+/**
+ * Classes to represent metadata of checkpoints saved to DFS. Since this is 
converted to JSON, any
+ * changes to this MUST be backward-compatible.
+ */
+case class RocksDBCheckpointMetadata(
+sstFiles: Seq[RocksDBSstFile],
+logFiles: Seq[RocksDBLogFile],
+numKeys: Long) {
+  import RocksDBCheckpointMetadata._
+
+  def json: String = {
+// We turn this field into a null to avoid write a empty logFiles field in 
the json.
+val nullified = if (logFiles.isEmpty) this.copy(logFiles = null) else this
+mapper.writeValueAsString(nullified)
+  }
+
+  def prettyJson: String = 
Serialization.writePretty(this)(RocksDBCheckpointMetadata.format)
+
+  def writeToFile(metadataFile: File): Unit = {
+val writer = Files.newBufferedWriter(metadataFile.toPath, UTF_8)
+try {
+  writer.write(s"v$VERSION\n")
+  writer.write(this.json)
+} finally {
+  writer.close()
+}
+  }
+
+  def immutableFiles: Seq[RocksDBImmutableFile] = sstFiles ++ logFiles
+}
+
+/** Helper class for [[RocksDBCheckpointMetadata]] */
+object RocksDBCheckpointMetadata {
+  val VERSION = 1
+
+  implicit val format = Serialization.formats(NoTypeHints)
+
+  /** Used to convert between classes and JSON. */
+  lazy val mapper = {
+val _mapper = new ObjectMapper with ScalaObjectMapper
+_mapper.setSerializationInclusion(Include.NON_ABSENT)
+_mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
+_mapper.registerModule(DefaultScalaModule)
+_mapper
+  }
+
+  def readFromFile(metadataFile: File): RocksDBCheckpointMetadata = {
+val reader = Files.newBufferedReader(metadataFile.toPath, UTF_8)
+try {
+  val versionLine = reader.readLine()
+  if (versionLine != s"v$VERSION") {
+throw new IllegalStateException(
+  s"Cannot read RocksDB checkpoint metadata of version $versionLine")
+  }
+  Serialization.read[RocksDBCheckpointMetadata](reader)
+} finally {
+  reader.close()
+}
+  }
+
+  def apply(rocksDBFiles: Seq[RocksDBImmutableFile], numKeys: Long): 
RocksDBCheckpointMetadata = {
+val sstFiles = rocksDBFiles.collect { case file: RocksDBSstFile => file }
+val logFiles = rocksDBFiles.collect { case file: RocksDBLogFile => file }
+
+RocksDBCheckpointMetadata(sstFiles, logFiles, numKeys)
+  }
+}
+
+/**
+ * A RocksDBImmutableFile maintains a mapping between a local RocksDB file 
name and the name of
+ * its copy on DFS. Since these files are immutable, their DFS copies can be 
reused.
+ */
+sealed trait RocksDBImmutableFile {
+  def localFileName: String
+  def dfsFileName: String
+  def sizeBytes: Long
+
+  /**
+   * Whether another local file is same as the file described by this class.
+   * A file is same only when the name and the size are same.
+   */
+  def isSameFile(otherFile: File): Boolean = {
+otherFile.getName == localFileName && otherFile.length() == sizeBytes
+  }
+}
+
+/**
+ * Class to represent a RocksDB SST file. Since this is converted to JSON,
+ * any changes to these MUST be backward-compatible.
+ */
+private[sql] case class RocksDBSstFile(
+localFileName: String,
+dfsSstFileName: String,
+sizeBytes: Long) extends RocksDBImmutableFile {
+
+  override def dfsFileName: String = dfsSstFileName
+}
+
+/**
+ * Class to represent a RocksDB Log file. Since this is converted to JSON,
+ * any changes to these MUST be 

[GitHub] [spark] xuanyuanking commented on a change in pull request #32272: [SPARK-35172][SS] The implementation of RocksDBCheckpointMetadata

2021-05-25 Thread GitBox


xuanyuanking commented on a change in pull request #32272:
URL: https://github.com/apache/spark/pull/32272#discussion_r638519692



##
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDBFileManager.scala
##
@@ -0,0 +1,165 @@
+/*
+ * 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.sql.execution.streaming.state
+
+import java.io.File
+import java.nio.charset.StandardCharsets.UTF_8
+import java.nio.file.Files
+
+import scala.collection.Seq
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include
+import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
+import com.fasterxml.jackson.module.scala.{DefaultScalaModule, 
ScalaObjectMapper}
+import org.json4s.NoTypeHints
+import org.json4s.jackson.Serialization
+
+/**
+ * Classes to represent metadata of checkpoints saved to DFS. Since this is 
converted to JSON, any
+ * changes to this MUST be backward-compatible.
+ */
+case class RocksDBCheckpointMetadata(
+sstFiles: Seq[RocksDBSstFile],
+logFiles: Seq[RocksDBLogFile],
+numKeys: Long) {
+  import RocksDBCheckpointMetadata._
+
+  def json: String = {
+// We turn this field into a null to avoid write a empty logFiles field in 
the json.
+val nullified = if (logFiles.isEmpty) this.copy(logFiles = null) else this
+mapper.writeValueAsString(nullified)
+  }
+
+  def prettyJson: String = 
Serialization.writePretty(this)(RocksDBCheckpointMetadata.format)
+
+  def writeToFile(metadataFile: File): Unit = {
+val writer = Files.newBufferedWriter(metadataFile.toPath, UTF_8)
+try {
+  writer.write(s"v$VERSION\n")
+  writer.write(this.json)
+} finally {
+  writer.close()
+}
+  }
+
+  def immutableFiles: Seq[RocksDBImmutableFile] = sstFiles ++ logFiles
+}
+
+/** Helper class for [[RocksDBCheckpointMetadata]] */
+object RocksDBCheckpointMetadata {
+  val VERSION = 1
+
+  implicit val format = Serialization.formats(NoTypeHints)
+
+  /** Used to convert between classes and JSON. */
+  lazy val mapper = {
+val _mapper = new ObjectMapper with ScalaObjectMapper
+_mapper.setSerializationInclusion(Include.NON_ABSENT)
+_mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
+_mapper.registerModule(DefaultScalaModule)
+_mapper
+  }
+
+  def readFromFile(metadataFile: File): RocksDBCheckpointMetadata = {
+val reader = Files.newBufferedReader(metadataFile.toPath, UTF_8)
+try {
+  val versionLine = reader.readLine()
+  if (versionLine != s"v$VERSION") {
+throw new IllegalStateException(
+  s"Cannot read RocksDB checkpoint metadata of version $versionLine")
+  }
+  Serialization.read[RocksDBCheckpointMetadata](reader)
+} finally {
+  reader.close()
+}
+  }
+
+  def apply(rocksDBFiles: Seq[RocksDBImmutableFile], numKeys: Long): 
RocksDBCheckpointMetadata = {
+val sstFiles = rocksDBFiles.collect { case file: RocksDBSstFile => file }
+val logFiles = rocksDBFiles.collect { case file: RocksDBLogFile => file }
+
+RocksDBCheckpointMetadata(sstFiles, logFiles, numKeys)
+  }
+}
+
+/**
+ * A RocksDBImmutableFile maintains a mapping between a local RocksDB file 
name and the name of
+ * its copy on DFS. Since these files are immutable, their DFS copies can be 
reused.
+ */
+sealed trait RocksDBImmutableFile {
+  def localFileName: String
+  def dfsFileName: String
+  def sizeBytes: Long
+
+  /**
+   * Whether another local file is same as the file described by this class.
+   * A file is same only when the name and the size are same.
+   */
+  def isSameFile(otherFile: File): Boolean = {
+otherFile.getName == localFileName && otherFile.length() == sizeBytes
+  }
+}
+
+/**
+ * Class to represent a RocksDB SST file. Since this is converted to JSON,
+ * any changes to these MUST be backward-compatible.
+ */
+private[sql] case class RocksDBSstFile(
+localFileName: String,
+dfsSstFileName: String,
+sizeBytes: Long) extends RocksDBImmutableFile {
+
+  override def dfsFileName: String = dfsSstFileName
+}
+
+/**
+ * Class to represent a RocksDB Log file. Since this is converted to JSON,
+ * any changes to these MUST be 

[GitHub] [spark] xuanyuanking commented on a change in pull request #32272: [SPARK-35172][SS] The implementation of RocksDBCheckpointMetadata

2021-05-24 Thread GitBox


xuanyuanking commented on a change in pull request #32272:
URL: https://github.com/apache/spark/pull/32272#discussion_r638383948



##
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDBFileManager.scala
##
@@ -0,0 +1,165 @@
+/*
+ * 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.sql.execution.streaming.state
+
+import java.io.File
+import java.nio.charset.StandardCharsets.UTF_8
+import java.nio.file.Files
+
+import scala.collection.Seq
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include
+import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
+import com.fasterxml.jackson.module.scala.{DefaultScalaModule, 
ScalaObjectMapper}
+import org.json4s.NoTypeHints
+import org.json4s.jackson.Serialization
+
+/**
+ * Classes to represent metadata of checkpoints saved to DFS. Since this is 
converted to JSON, any
+ * changes to this MUST be backward-compatible.
+ */
+case class RocksDBCheckpointMetadata(
+sstFiles: Seq[RocksDBSstFile],
+logFiles: Seq[RocksDBLogFile],
+numKeys: Long) {
+  import RocksDBCheckpointMetadata._
+
+  def json: String = {
+// We turn this field into a null to avoid write a empty logFiles field in 
the json.
+val nullified = if (logFiles.isEmpty) this.copy(logFiles = null) else this
+mapper.writeValueAsString(nullified)
+  }
+
+  def prettyJson: String = 
Serialization.writePretty(this)(RocksDBCheckpointMetadata.format)
+
+  def writeToFile(metadataFile: File): Unit = {
+val writer = Files.newBufferedWriter(metadataFile.toPath, UTF_8)
+try {
+  writer.write(s"v$VERSION\n")
+  writer.write(this.json)
+} finally {
+  writer.close()
+}
+  }
+
+  def immutableFiles: Seq[RocksDBImmutableFile] = sstFiles ++ logFiles
+}
+
+/** Helper class for [[RocksDBCheckpointMetadata]] */
+object RocksDBCheckpointMetadata {
+  val VERSION = 1
+
+  implicit val format = Serialization.formats(NoTypeHints)
+
+  /** Used to convert between classes and JSON. */
+  lazy val mapper = {
+val _mapper = new ObjectMapper with ScalaObjectMapper
+_mapper.setSerializationInclusion(Include.NON_ABSENT)
+_mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
+_mapper.registerModule(DefaultScalaModule)
+_mapper
+  }
+
+  def readFromFile(metadataFile: File): RocksDBCheckpointMetadata = {
+val reader = Files.newBufferedReader(metadataFile.toPath, UTF_8)
+try {
+  val versionLine = reader.readLine()
+  if (versionLine != s"v$VERSION") {
+throw new IllegalStateException(
+  s"Cannot read RocksDB checkpoint metadata of version $versionLine")
+  }
+  Serialization.read[RocksDBCheckpointMetadata](reader)
+} finally {
+  reader.close()
+}
+  }
+
+  def apply(rocksDBFiles: Seq[RocksDBImmutableFile], numKeys: Long): 
RocksDBCheckpointMetadata = {
+val sstFiles = rocksDBFiles.collect { case file: RocksDBSstFile => file }
+val logFiles = rocksDBFiles.collect { case file: RocksDBLogFile => file }
+
+RocksDBCheckpointMetadata(sstFiles, logFiles, numKeys)
+  }
+}
+
+/**
+ * A RocksDBImmutableFile maintains a mapping between a local RocksDB file 
name and the name of
+ * its copy on DFS. Since these files are immutable, their DFS copies can be 
reused.
+ */
+sealed trait RocksDBImmutableFile {
+  def localFileName: String
+  def dfsFileName: String
+  def sizeBytes: Long
+
+  /**
+   * Whether another local file is same as the file described by this class.
+   * A file is same only when the name and the size are same.
+   */
+  def isSameFile(otherFile: File): Boolean = {
+otherFile.getName == localFileName && otherFile.length() == sizeBytes
+  }
+}
+
+/**
+ * Class to represent a RocksDB SST file. Since this is converted to JSON,
+ * any changes to these MUST be backward-compatible.
+ */
+private[sql] case class RocksDBSstFile(
+localFileName: String,
+dfsSstFileName: String,
+sizeBytes: Long) extends RocksDBImmutableFile {
+
+  override def dfsFileName: String = dfsSstFileName
+}
+
+/**
+ * Class to represent a RocksDB Log file. Since this is converted to JSON,
+ * any changes to these MUST be 

[GitHub] [spark] xuanyuanking commented on a change in pull request #32272: [SPARK-35172][SS] The implementation of RocksDBCheckpointMetadata

2021-05-24 Thread GitBox


xuanyuanking commented on a change in pull request #32272:
URL: https://github.com/apache/spark/pull/32272#discussion_r638132159



##
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDBFileManager.scala
##
@@ -0,0 +1,165 @@
+/*
+ * 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.sql.execution.streaming.state
+
+import java.io.File
+import java.nio.charset.StandardCharsets.UTF_8
+import java.nio.file.Files
+
+import scala.collection.Seq
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include
+import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
+import com.fasterxml.jackson.module.scala.{DefaultScalaModule, 
ScalaObjectMapper}
+import org.json4s.NoTypeHints
+import org.json4s.jackson.Serialization
+
+/**
+ * Classes to represent metadata of checkpoints saved to DFS. Since this is 
converted to JSON, any
+ * changes to this MUST be backward-compatible.
+ */
+case class RocksDBCheckpointMetadata(
+sstFiles: Seq[RocksDBSstFile],
+logFiles: Seq[RocksDBLogFile],
+numKeys: Long) {
+  import RocksDBCheckpointMetadata._
+
+  def json: String = {
+// We turn this field into a null to avoid write a empty logFiles field in 
the json.
+val nullified = if (logFiles.isEmpty) this.copy(logFiles = null) else this
+mapper.writeValueAsString(nullified)
+  }
+
+  def prettyJson: String = 
Serialization.writePretty(this)(RocksDBCheckpointMetadata.format)
+
+  def writeToFile(metadataFile: File): Unit = {
+val writer = Files.newBufferedWriter(metadataFile.toPath, UTF_8)
+try {
+  writer.write(s"v$VERSION\n")
+  writer.write(this.json)
+} finally {
+  writer.close()
+}
+  }
+
+  def immutableFiles: Seq[RocksDBImmutableFile] = sstFiles ++ logFiles
+}
+
+/** Helper class for [[RocksDBCheckpointMetadata]] */
+object RocksDBCheckpointMetadata {
+  val VERSION = 1
+
+  implicit val format = Serialization.formats(NoTypeHints)
+
+  /** Used to convert between classes and JSON. */
+  lazy val mapper = {
+val _mapper = new ObjectMapper with ScalaObjectMapper
+_mapper.setSerializationInclusion(Include.NON_ABSENT)
+_mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
+_mapper.registerModule(DefaultScalaModule)
+_mapper
+  }
+
+  def readFromFile(metadataFile: File): RocksDBCheckpointMetadata = {
+val reader = Files.newBufferedReader(metadataFile.toPath, UTF_8)
+try {
+  val versionLine = reader.readLine()
+  if (versionLine != s"v$VERSION") {
+throw new IllegalStateException(
+  s"Cannot read RocksDB checkpoint metadata of version $versionLine")
+  }
+  Serialization.read[RocksDBCheckpointMetadata](reader)
+} finally {
+  reader.close()
+}
+  }
+
+  def apply(rocksDBFiles: Seq[RocksDBImmutableFile], numKeys: Long): 
RocksDBCheckpointMetadata = {
+val sstFiles = rocksDBFiles.collect { case file: RocksDBSstFile => file }
+val logFiles = rocksDBFiles.collect { case file: RocksDBLogFile => file }
+
+RocksDBCheckpointMetadata(sstFiles, logFiles, numKeys)
+  }
+}
+
+/**
+ * A RocksDBImmutableFile maintains a mapping between a local RocksDB file 
name and the name of
+ * its copy on DFS. Since these files are immutable, their DFS copies can be 
reused.
+ */
+sealed trait RocksDBImmutableFile {
+  def localFileName: String
+  def dfsFileName: String
+  def sizeBytes: Long
+
+  /**
+   * Whether another local file is same as the file described by this class.
+   * A file is same only when the name and the size are same.
+   */
+  def isSameFile(otherFile: File): Boolean = {
+otherFile.getName == localFileName && otherFile.length() == sizeBytes
+  }
+}
+
+/**
+ * Class to represent a RocksDB SST file. Since this is converted to JSON,
+ * any changes to these MUST be backward-compatible.
+ */
+private[sql] case class RocksDBSstFile(
+localFileName: String,
+dfsSstFileName: String,
+sizeBytes: Long) extends RocksDBImmutableFile {
+
+  override def dfsFileName: String = dfsSstFileName
+}
+
+/**
+ * Class to represent a RocksDB Log file. Since this is converted to JSON,
+ * any changes to these MUST be 

[GitHub] [spark] xuanyuanking commented on a change in pull request #32272: [SPARK-35172][SS] The implementation of RocksDBCheckpointMetadata

2021-05-24 Thread GitBox


xuanyuanking commented on a change in pull request #32272:
URL: https://github.com/apache/spark/pull/32272#discussion_r638126273



##
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDBFileManager.scala
##
@@ -0,0 +1,165 @@
+/*
+ * 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.sql.execution.streaming.state
+
+import java.io.File
+import java.nio.charset.StandardCharsets.UTF_8
+import java.nio.file.Files
+
+import scala.collection.Seq
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include
+import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
+import com.fasterxml.jackson.module.scala.{DefaultScalaModule, 
ScalaObjectMapper}
+import org.json4s.NoTypeHints
+import org.json4s.jackson.Serialization
+
+/**
+ * Classes to represent metadata of checkpoints saved to DFS. Since this is 
converted to JSON, any
+ * changes to this MUST be backward-compatible.
+ */
+case class RocksDBCheckpointMetadata(
+sstFiles: Seq[RocksDBSstFile],
+logFiles: Seq[RocksDBLogFile],
+numKeys: Long) {
+  import RocksDBCheckpointMetadata._
+
+  def json: String = {
+// We turn this field into a null to avoid write a empty logFiles field in 
the json.
+val nullified = if (logFiles.isEmpty) this.copy(logFiles = null) else this
+mapper.writeValueAsString(nullified)
+  }
+
+  def prettyJson: String = 
Serialization.writePretty(this)(RocksDBCheckpointMetadata.format)
+
+  def writeToFile(metadataFile: File): Unit = {
+val writer = Files.newBufferedWriter(metadataFile.toPath, UTF_8)
+try {
+  writer.write(s"v$VERSION\n")
+  writer.write(this.json)
+} finally {
+  writer.close()
+}
+  }
+
+  def immutableFiles: Seq[RocksDBImmutableFile] = sstFiles ++ logFiles
+}
+
+/** Helper class for [[RocksDBCheckpointMetadata]] */
+object RocksDBCheckpointMetadata {
+  val VERSION = 1
+
+  implicit val format = Serialization.formats(NoTypeHints)
+
+  /** Used to convert between classes and JSON. */
+  lazy val mapper = {
+val _mapper = new ObjectMapper with ScalaObjectMapper
+_mapper.setSerializationInclusion(Include.NON_ABSENT)
+_mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
+_mapper.registerModule(DefaultScalaModule)
+_mapper
+  }
+
+  def readFromFile(metadataFile: File): RocksDBCheckpointMetadata = {
+val reader = Files.newBufferedReader(metadataFile.toPath, UTF_8)
+try {
+  val versionLine = reader.readLine()
+  if (versionLine != s"v$VERSION") {
+throw new IllegalStateException(
+  s"Cannot read RocksDB checkpoint metadata of version $versionLine")
+  }
+  Serialization.read[RocksDBCheckpointMetadata](reader)
+} finally {
+  reader.close()
+}
+  }
+
+  def apply(rocksDBFiles: Seq[RocksDBImmutableFile], numKeys: Long): 
RocksDBCheckpointMetadata = {
+val sstFiles = rocksDBFiles.collect { case file: RocksDBSstFile => file }
+val logFiles = rocksDBFiles.collect { case file: RocksDBLogFile => file }
+
+RocksDBCheckpointMetadata(sstFiles, logFiles, numKeys)
+  }
+}
+
+/**
+ * A RocksDBImmutableFile maintains a mapping between a local RocksDB file 
name and the name of
+ * its copy on DFS. Since these files are immutable, their DFS copies can be 
reused.
+ */
+sealed trait RocksDBImmutableFile {
+  def localFileName: String
+  def dfsFileName: String
+  def sizeBytes: Long
+
+  /**
+   * Whether another local file is same as the file described by this class.
+   * A file is same only when the name and the size are same.
+   */
+  def isSameFile(otherFile: File): Boolean = {
+otherFile.getName == localFileName && otherFile.length() == sizeBytes
+  }
+}
+
+/**
+ * Class to represent a RocksDB SST file. Since this is converted to JSON,
+ * any changes to these MUST be backward-compatible.
+ */
+private[sql] case class RocksDBSstFile(
+localFileName: String,
+dfsSstFileName: String,
+sizeBytes: Long) extends RocksDBImmutableFile {
+
+  override def dfsFileName: String = dfsSstFileName
+}
+
+/**
+ * Class to represent a RocksDB Log file. Since this is converted to JSON,
+ * any changes to these MUST be 

[GitHub] [spark] xuanyuanking commented on a change in pull request #32272: [SPARK-35172][SS] The implementation of RocksDBCheckpointMetadata

2021-05-17 Thread GitBox


xuanyuanking commented on a change in pull request #32272:
URL: https://github.com/apache/spark/pull/32272#discussion_r633321491



##
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDBFileManager.scala
##
@@ -0,0 +1,165 @@
+/*
+ * 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.sql.execution.streaming.state
+
+import java.io.File
+import java.nio.charset.StandardCharsets.UTF_8
+import java.nio.file.Files
+
+import scala.collection.Seq
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include
+import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
+import com.fasterxml.jackson.module.scala.{DefaultScalaModule, 
ScalaObjectMapper}
+import org.json4s.NoTypeHints
+import org.json4s.jackson.Serialization
+
+/**
+ * Classes to represent metadata of checkpoints saved to DFS. Since this is 
converted to JSON, any
+ * changes to this MUST be backward-compatible.
+ */
+case class RocksDBCheckpointMetadata(
+sstFiles: Seq[RocksDBSstFile],
+logFiles: Seq[RocksDBLogFile],
+numKeys: Long) {
+  import RocksDBCheckpointMetadata._
+
+  def json: String = {
+// We turn this field into a null to avoid write a empty logFiles field in 
the json.
+val nullified = if (logFiles.isEmpty) this.copy(logFiles = null) else this
+mapper.writeValueAsString(nullified)
+  }
+
+  def prettyJson: String = 
Serialization.writePretty(this)(RocksDBCheckpointMetadata.format)
+
+  def writeToFile(metadataFile: File): Unit = {
+val writer = Files.newBufferedWriter(metadataFile.toPath, UTF_8)
+try {
+  writer.write(s"v$VERSION\n")
+  writer.write(this.json)
+} finally {
+  writer.close()
+}
+  }
+
+  def immutableFiles: Seq[RocksDBImmutableFile] = sstFiles ++ logFiles
+}
+
+/** Helper class for [[RocksDBCheckpointMetadata]] */
+object RocksDBCheckpointMetadata {
+  val VERSION = 1
+
+  implicit val format = Serialization.formats(NoTypeHints)
+
+  /** Used to convert between classes and JSON. */
+  lazy val mapper = {
+val _mapper = new ObjectMapper with ScalaObjectMapper
+_mapper.setSerializationInclusion(Include.NON_ABSENT)
+_mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
+_mapper.registerModule(DefaultScalaModule)
+_mapper
+  }
+
+  def readFromFile(metadataFile: File): RocksDBCheckpointMetadata = {
+val reader = Files.newBufferedReader(metadataFile.toPath, UTF_8)
+try {
+  val versionLine = reader.readLine()
+  if (versionLine != s"v$VERSION") {
+throw new IllegalStateException(
+  s"Cannot read RocksDB checkpoint metadata of version $versionLine")
+  }
+  Serialization.read[RocksDBCheckpointMetadata](reader)
+} finally {
+  reader.close()
+}
+  }
+
+  def apply(rocksDBFiles: Seq[RocksDBImmutableFile], numKeys: Long): 
RocksDBCheckpointMetadata = {
+val sstFiles = rocksDBFiles.collect { case file: RocksDBSstFile => file }
+val logFiles = rocksDBFiles.collect { case file: RocksDBLogFile => file }
+
+RocksDBCheckpointMetadata(sstFiles, logFiles, numKeys)
+  }
+}
+
+/**
+ * A RocksDBImmutableFile maintains a mapping between a local RocksDB file 
name and the name of
+ * its copy on DFS. Since these files are immutable, their DFS copies can be 
reused.
+ */
+sealed trait RocksDBImmutableFile {
+  def localFileName: String
+  def dfsFileName: String
+  def sizeBytes: Long
+
+  /**
+   * Whether another local file is same as the file described by this class.
+   * A file is same only when the name and the size are same.
+   */
+  def isSameFile(otherFile: File): Boolean = {
+otherFile.getName == localFileName && otherFile.length() == sizeBytes
+  }
+}
+
+/**
+ * Class to represent a RocksDB SST file. Since this is converted to JSON,
+ * any changes to these MUST be backward-compatible.
+ */
+private[sql] case class RocksDBSstFile(
+localFileName: String,
+dfsSstFileName: String,
+sizeBytes: Long) extends RocksDBImmutableFile {
+
+  override def dfsFileName: String = dfsSstFileName
+}
+
+/**
+ * Class to represent a RocksDB Log file. Since this is converted to JSON,
+ * any changes to these MUST be 

[GitHub] [spark] xuanyuanking commented on a change in pull request #32272: [SPARK-35172][SS] The implementation of RocksDBCheckpointMetadata

2021-05-17 Thread GitBox


xuanyuanking commented on a change in pull request #32272:
URL: https://github.com/apache/spark/pull/32272#discussion_r633321491



##
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDBFileManager.scala
##
@@ -0,0 +1,165 @@
+/*
+ * 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.sql.execution.streaming.state
+
+import java.io.File
+import java.nio.charset.StandardCharsets.UTF_8
+import java.nio.file.Files
+
+import scala.collection.Seq
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include
+import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
+import com.fasterxml.jackson.module.scala.{DefaultScalaModule, 
ScalaObjectMapper}
+import org.json4s.NoTypeHints
+import org.json4s.jackson.Serialization
+
+/**
+ * Classes to represent metadata of checkpoints saved to DFS. Since this is 
converted to JSON, any
+ * changes to this MUST be backward-compatible.
+ */
+case class RocksDBCheckpointMetadata(
+sstFiles: Seq[RocksDBSstFile],
+logFiles: Seq[RocksDBLogFile],
+numKeys: Long) {
+  import RocksDBCheckpointMetadata._
+
+  def json: String = {
+// We turn this field into a null to avoid write a empty logFiles field in 
the json.
+val nullified = if (logFiles.isEmpty) this.copy(logFiles = null) else this
+mapper.writeValueAsString(nullified)
+  }
+
+  def prettyJson: String = 
Serialization.writePretty(this)(RocksDBCheckpointMetadata.format)
+
+  def writeToFile(metadataFile: File): Unit = {
+val writer = Files.newBufferedWriter(metadataFile.toPath, UTF_8)
+try {
+  writer.write(s"v$VERSION\n")
+  writer.write(this.json)
+} finally {
+  writer.close()
+}
+  }
+
+  def immutableFiles: Seq[RocksDBImmutableFile] = sstFiles ++ logFiles
+}
+
+/** Helper class for [[RocksDBCheckpointMetadata]] */
+object RocksDBCheckpointMetadata {
+  val VERSION = 1
+
+  implicit val format = Serialization.formats(NoTypeHints)
+
+  /** Used to convert between classes and JSON. */
+  lazy val mapper = {
+val _mapper = new ObjectMapper with ScalaObjectMapper
+_mapper.setSerializationInclusion(Include.NON_ABSENT)
+_mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
+_mapper.registerModule(DefaultScalaModule)
+_mapper
+  }
+
+  def readFromFile(metadataFile: File): RocksDBCheckpointMetadata = {
+val reader = Files.newBufferedReader(metadataFile.toPath, UTF_8)
+try {
+  val versionLine = reader.readLine()
+  if (versionLine != s"v$VERSION") {
+throw new IllegalStateException(
+  s"Cannot read RocksDB checkpoint metadata of version $versionLine")
+  }
+  Serialization.read[RocksDBCheckpointMetadata](reader)
+} finally {
+  reader.close()
+}
+  }
+
+  def apply(rocksDBFiles: Seq[RocksDBImmutableFile], numKeys: Long): 
RocksDBCheckpointMetadata = {
+val sstFiles = rocksDBFiles.collect { case file: RocksDBSstFile => file }
+val logFiles = rocksDBFiles.collect { case file: RocksDBLogFile => file }
+
+RocksDBCheckpointMetadata(sstFiles, logFiles, numKeys)
+  }
+}
+
+/**
+ * A RocksDBImmutableFile maintains a mapping between a local RocksDB file 
name and the name of
+ * its copy on DFS. Since these files are immutable, their DFS copies can be 
reused.
+ */
+sealed trait RocksDBImmutableFile {
+  def localFileName: String
+  def dfsFileName: String
+  def sizeBytes: Long
+
+  /**
+   * Whether another local file is same as the file described by this class.
+   * A file is same only when the name and the size are same.
+   */
+  def isSameFile(otherFile: File): Boolean = {
+otherFile.getName == localFileName && otherFile.length() == sizeBytes
+  }
+}
+
+/**
+ * Class to represent a RocksDB SST file. Since this is converted to JSON,
+ * any changes to these MUST be backward-compatible.
+ */
+private[sql] case class RocksDBSstFile(
+localFileName: String,
+dfsSstFileName: String,
+sizeBytes: Long) extends RocksDBImmutableFile {
+
+  override def dfsFileName: String = dfsSstFileName
+}
+
+/**
+ * Class to represent a RocksDB Log file. Since this is converted to JSON,
+ * any changes to these MUST be 

[GitHub] [spark] xuanyuanking commented on a change in pull request #32272: [SPARK-35172][SS] The implementation of RocksDBCheckpointMetadata

2021-05-13 Thread GitBox


xuanyuanking commented on a change in pull request #32272:
URL: https://github.com/apache/spark/pull/32272#discussion_r631689463



##
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDBFileManager.scala
##
@@ -0,0 +1,165 @@
+/*
+ * 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.sql.execution.streaming.state
+
+import java.io.File
+import java.nio.charset.StandardCharsets.UTF_8
+import java.nio.file.Files
+
+import scala.collection.Seq
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include
+import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
+import com.fasterxml.jackson.module.scala.{DefaultScalaModule, 
ScalaObjectMapper}
+import org.json4s.NoTypeHints
+import org.json4s.jackson.Serialization
+
+/**
+ * Classes to represent metadata of checkpoints saved to DFS. Since this is 
converted to JSON, any
+ * changes to this MUST be backward-compatible.
+ */
+case class RocksDBCheckpointMetadata(
+sstFiles: Seq[RocksDBSstFile],
+logFiles: Seq[RocksDBLogFile],
+numKeys: Long) {
+  import RocksDBCheckpointMetadata._
+
+  def json: String = {
+// We turn this field into a null to avoid write a empty logFiles field in 
the json.
+val nullified = if (logFiles.isEmpty) this.copy(logFiles = null) else this

Review comment:
   Yes, the `logFiles` field not always has value.




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



[GitHub] [spark] xuanyuanking commented on a change in pull request #32272: [SPARK-35172][SS] The implementation of RocksDBCheckpointMetadata

2021-05-13 Thread GitBox


xuanyuanking commented on a change in pull request #32272:
URL: https://github.com/apache/spark/pull/32272#discussion_r631689200



##
File path: 
sql/core/src/test/scala/org/apache/spark/sql/execution/streaming/state/RocksDBSuite.scala
##
@@ -0,0 +1,65 @@
+/*
+ * 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.sql.execution.streaming.state
+
+import java.io._
+import java.nio.charset.Charset
+
+import org.apache.commons.io.FileUtils
+
+import org.apache.spark._
+import org.apache.spark.util.Utils
+
+class RocksDBSuite extends SparkFunSuite {
+
+  test("checkpoint metadata serde roundtrip") {
+def checkJsonRoundtrip(metadata: RocksDBCheckpointMetadata, json: String): 
Unit = {
+  assert(metadata.json == json)
+  withTempDirectory { dir =>
+val file = new File(dir, "json")
+FileUtils.write(file, s"v1\n$json", Charset.defaultCharset)
+assert(metadata == RocksDBCheckpointMetadata.readFromFile(file))
+  }
+}
+val sstFiles = Seq(RocksDBSstFile("1.sst", "1-uuid.sst", 
12345678901234L))
+val logFiles = Seq(RocksDBLogFile("1.log", "1-uuid.log", 
12345678901234L))
+
+// scalastyle:off line.size.limit
+// should always include sstFiles and numKeys
+checkJsonRoundtrip(
+  RocksDBCheckpointMetadata(Seq.empty, 0L),
+  """{"sstFiles":[],"numKeys":0}"""
+)
+// shouldn't include the "logFiles" field in json when it's empty
+checkJsonRoundtrip(
+  RocksDBCheckpointMetadata(sstFiles, 12345678901234L),
+  
"""{"sstFiles":[{"localFileName":"1.sst","dfsSstFileName":"1-uuid.sst","sizeBytes":12345678901234}],"numKeys":12345678901234}"""
+)
+checkJsonRoundtrip(
+  RocksDBCheckpointMetadata(sstFiles, logFiles, 12345678901234L),
+  
"""{"sstFiles":[{"localFileName":"1.sst","dfsSstFileName":"1-uuid.sst","sizeBytes":12345678901234}],"logFiles":[{"localFileName":"1.log","dfsLogFileName":"1-uuid.log","sizeBytes":12345678901234}],"numKeys":12345678901234}""")
+// scalastyle:on line.size.limit
+  }
+
+  private def withTempDirectory(f: File => Unit): Unit = {

Review comment:
   Ah yes. Let me update.




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



[GitHub] [spark] xuanyuanking commented on a change in pull request #32272: [SPARK-35172][SS] The implementation of RocksDBCheckpointMetadata

2021-05-13 Thread GitBox


xuanyuanking commented on a change in pull request #32272:
URL: https://github.com/apache/spark/pull/32272#discussion_r631688986



##
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDBFileManager.scala
##
@@ -0,0 +1,165 @@
+/*
+ * 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.sql.execution.streaming.state
+
+import java.io.File
+import java.nio.charset.StandardCharsets.UTF_8
+import java.nio.file.Files
+
+import scala.collection.Seq
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include
+import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
+import com.fasterxml.jackson.module.scala.{DefaultScalaModule, 
ScalaObjectMapper}
+import org.json4s.NoTypeHints
+import org.json4s.jackson.Serialization
+
+/**
+ * Classes to represent metadata of checkpoints saved to DFS. Since this is 
converted to JSON, any
+ * changes to this MUST be backward-compatible.
+ */
+case class RocksDBCheckpointMetadata(
+sstFiles: Seq[RocksDBSstFile],
+logFiles: Seq[RocksDBLogFile],
+numKeys: Long) {
+  import RocksDBCheckpointMetadata._
+
+  def json: String = {
+// We turn this field into a null to avoid write a empty logFiles field in 
the json.
+val nullified = if (logFiles.isEmpty) this.copy(logFiles = null) else this
+mapper.writeValueAsString(nullified)
+  }
+
+  def prettyJson: String = 
Serialization.writePretty(this)(RocksDBCheckpointMetadata.format)

Review comment:
   The only difference is the `logFiles` fields. Actually the `prettyJson` 
field is for providing a readable string for log. `json` field is for files 
writing.




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



[GitHub] [spark] xuanyuanking commented on a change in pull request #32272: [SPARK-35172][SS] The implementation of RocksDBCheckpointMetadata

2021-04-26 Thread GitBox


xuanyuanking commented on a change in pull request #32272:
URL: https://github.com/apache/spark/pull/32272#discussion_r619785921



##
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDBFileManager.scala
##
@@ -0,0 +1,165 @@
+/*
+ * 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.sql.execution.streaming.state
+
+import java.io.File
+import java.nio.charset.StandardCharsets.UTF_8
+import java.nio.file.Files
+
+import scala.collection.Seq
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include
+import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
+import com.fasterxml.jackson.module.scala.{DefaultScalaModule, 
ScalaObjectMapper}
+import org.json4s.NoTypeHints
+import org.json4s.jackson.Serialization
+
+/**
+ * Classes to represent metadata of checkpoints saved to DFS. Since this is 
converted to JSON, any
+ * changes to this MUST be backward-compatible.
+ */
+case class RocksDBCheckpointMetadata(
+sstFiles: Seq[RocksDBSstFile],
+logFiles: Seq[RocksDBLogFile],
+numKeys: Long) {
+  import RocksDBCheckpointMetadata._
+
+  def json: String = {
+// We turn this field into a null to avoid write a empty logFiles field in 
the json.
+val nullified = if (logFiles.isEmpty) this.copy(logFiles = null) else this

Review comment:
   It's related to the usage for RocksDB, we don't always have log files. 
But we must have sst files.

##
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDBFileManager.scala
##
@@ -0,0 +1,165 @@
+/*
+ * 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.sql.execution.streaming.state
+
+import java.io.File
+import java.nio.charset.StandardCharsets.UTF_8
+import java.nio.file.Files
+
+import scala.collection.Seq
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include
+import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
+import com.fasterxml.jackson.module.scala.{DefaultScalaModule, 
ScalaObjectMapper}
+import org.json4s.NoTypeHints
+import org.json4s.jackson.Serialization
+
+/**
+ * Classes to represent metadata of checkpoints saved to DFS. Since this is 
converted to JSON, any
+ * changes to this MUST be backward-compatible.
+ */
+case class RocksDBCheckpointMetadata(
+sstFiles: Seq[RocksDBSstFile],
+logFiles: Seq[RocksDBLogFile],
+numKeys: Long) {
+  import RocksDBCheckpointMetadata._
+
+  def json: String = {
+// We turn this field into a null to avoid write a empty logFiles field in 
the json.
+val nullified = if (logFiles.isEmpty) this.copy(logFiles = null) else this
+mapper.writeValueAsString(nullified)
+  }
+
+  def prettyJson: String = 
Serialization.writePretty(this)(RocksDBCheckpointMetadata.format)
+
+  def writeToFile(metadataFile: File): Unit = {
+val writer = Files.newBufferedWriter(metadataFile.toPath, UTF_8)
+try {
+  writer.write(s"v$VERSION\n")
+  writer.write(this.json)
+} finally {
+  writer.close()
+}
+  }
+
+  def immutableFiles: Seq[RocksDBImmutableFile] = sstFiles ++ logFiles
+}
+
+/** Helper class for [[RocksDBCheckpointMetadata]] */
+object RocksDBCheckpointMetadata {
+  val VERSION = 1
+
+  implicit val format = Serialization.formats(NoTypeHints)
+
+  /** Used to convert between classes and JSON. */
+  lazy val mapper = {
+val _mapper = new ObjectMapper with 

[GitHub] [spark] xuanyuanking commented on a change in pull request #32272: [SPARK-35172][SS] The implementation of RocksDBCheckpointMetadata

2021-04-25 Thread GitBox


xuanyuanking commented on a change in pull request #32272:
URL: https://github.com/apache/spark/pull/32272#discussion_r619787523



##
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDBFileManager.scala
##
@@ -0,0 +1,165 @@
+/*
+ * 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.sql.execution.streaming.state
+
+import java.io.File
+import java.nio.charset.StandardCharsets.UTF_8
+import java.nio.file.Files
+
+import scala.collection.Seq
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include
+import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
+import com.fasterxml.jackson.module.scala.{DefaultScalaModule, 
ScalaObjectMapper}
+import org.json4s.NoTypeHints
+import org.json4s.jackson.Serialization
+
+/**
+ * Classes to represent metadata of checkpoints saved to DFS. Since this is 
converted to JSON, any
+ * changes to this MUST be backward-compatible.
+ */
+case class RocksDBCheckpointMetadata(
+sstFiles: Seq[RocksDBSstFile],
+logFiles: Seq[RocksDBLogFile],
+numKeys: Long) {
+  import RocksDBCheckpointMetadata._
+
+  def json: String = {
+// We turn this field into a null to avoid write a empty logFiles field in 
the json.
+val nullified = if (logFiles.isEmpty) this.copy(logFiles = null) else this
+mapper.writeValueAsString(nullified)
+  }
+
+  def prettyJson: String = 
Serialization.writePretty(this)(RocksDBCheckpointMetadata.format)
+
+  def writeToFile(metadataFile: File): Unit = {
+val writer = Files.newBufferedWriter(metadataFile.toPath, UTF_8)
+try {
+  writer.write(s"v$VERSION\n")
+  writer.write(this.json)
+} finally {
+  writer.close()
+}
+  }
+
+  def immutableFiles: Seq[RocksDBImmutableFile] = sstFiles ++ logFiles
+}
+
+/** Helper class for [[RocksDBCheckpointMetadata]] */
+object RocksDBCheckpointMetadata {
+  val VERSION = 1
+
+  implicit val format = Serialization.formats(NoTypeHints)
+
+  /** Used to convert between classes and JSON. */
+  lazy val mapper = {
+val _mapper = new ObjectMapper with ScalaObjectMapper
+_mapper.setSerializationInclusion(Include.NON_ABSENT)
+_mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
+_mapper.registerModule(DefaultScalaModule)
+_mapper
+  }
+
+  def readFromFile(metadataFile: File): RocksDBCheckpointMetadata = {
+val reader = Files.newBufferedReader(metadataFile.toPath, UTF_8)
+try {
+  val versionLine = reader.readLine()
+  if (versionLine != s"v$VERSION") {
+throw new IllegalStateException(
+  s"Cannot read RocksDB checkpoint metadata of version $versionLine")
+  }
+  Serialization.read[RocksDBCheckpointMetadata](reader)
+} finally {
+  reader.close()
+}
+  }
+
+  def apply(rocksDBFiles: Seq[RocksDBImmutableFile], numKeys: Long): 
RocksDBCheckpointMetadata = {
+val sstFiles = rocksDBFiles.collect { case file: RocksDBSstFile => file }
+val logFiles = rocksDBFiles.collect { case file: RocksDBLogFile => file }
+
+RocksDBCheckpointMetadata(sstFiles, logFiles, numKeys)
+  }
+}
+
+/**
+ * A RocksDBImmutableFile maintains a mapping between a local RocksDB file 
name and the name of
+ * its copy on DFS. Since these files are immutable, their DFS copies can be 
reused.
+ */
+sealed trait RocksDBImmutableFile {
+  def localFileName: String
+  def dfsFileName: String
+  def sizeBytes: Long
+
+  /**
+   * Whether another local file is same as the file described by this class.
+   * A file is same only when the name and the size are same.
+   */
+  def isSameFile(otherFile: File): Boolean = {
+otherFile.getName == localFileName && otherFile.length() == sizeBytes
+  }

Review comment:
   The DFS file name contains UUID, it shouldn't be the same. Normally we 
use the local file name to filter whether the file is existing locally.




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




[GitHub] [spark] xuanyuanking commented on a change in pull request #32272: [SPARK-35172][SS] The implementation of RocksDBCheckpointMetadata

2021-04-25 Thread GitBox


xuanyuanking commented on a change in pull request #32272:
URL: https://github.com/apache/spark/pull/32272#discussion_r619786926



##
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDBFileManager.scala
##
@@ -0,0 +1,165 @@
+/*
+ * 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.sql.execution.streaming.state
+
+import java.io.File
+import java.nio.charset.StandardCharsets.UTF_8
+import java.nio.file.Files
+
+import scala.collection.Seq
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include
+import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
+import com.fasterxml.jackson.module.scala.{DefaultScalaModule, 
ScalaObjectMapper}
+import org.json4s.NoTypeHints
+import org.json4s.jackson.Serialization
+
+/**
+ * Classes to represent metadata of checkpoints saved to DFS. Since this is 
converted to JSON, any
+ * changes to this MUST be backward-compatible.
+ */
+case class RocksDBCheckpointMetadata(
+sstFiles: Seq[RocksDBSstFile],
+logFiles: Seq[RocksDBLogFile],
+numKeys: Long) {
+  import RocksDBCheckpointMetadata._
+
+  def json: String = {
+// We turn this field into a null to avoid write a empty logFiles field in 
the json.
+val nullified = if (logFiles.isEmpty) this.copy(logFiles = null) else this
+mapper.writeValueAsString(nullified)
+  }
+
+  def prettyJson: String = 
Serialization.writePretty(this)(RocksDBCheckpointMetadata.format)
+
+  def writeToFile(metadataFile: File): Unit = {
+val writer = Files.newBufferedWriter(metadataFile.toPath, UTF_8)
+try {
+  writer.write(s"v$VERSION\n")
+  writer.write(this.json)
+} finally {
+  writer.close()
+}
+  }
+
+  def immutableFiles: Seq[RocksDBImmutableFile] = sstFiles ++ logFiles
+}
+
+/** Helper class for [[RocksDBCheckpointMetadata]] */
+object RocksDBCheckpointMetadata {
+  val VERSION = 1
+
+  implicit val format = Serialization.formats(NoTypeHints)
+
+  /** Used to convert between classes and JSON. */
+  lazy val mapper = {
+val _mapper = new ObjectMapper with ScalaObjectMapper
+_mapper.setSerializationInclusion(Include.NON_ABSENT)
+_mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
+_mapper.registerModule(DefaultScalaModule)
+_mapper
+  }
+
+  def readFromFile(metadataFile: File): RocksDBCheckpointMetadata = {
+val reader = Files.newBufferedReader(metadataFile.toPath, UTF_8)
+try {
+  val versionLine = reader.readLine()
+  if (versionLine != s"v$VERSION") {
+throw new IllegalStateException(
+  s"Cannot read RocksDB checkpoint metadata of version $versionLine")
+  }
+  Serialization.read[RocksDBCheckpointMetadata](reader)
+} finally {
+  reader.close()
+}
+  }
+
+  def apply(rocksDBFiles: Seq[RocksDBImmutableFile], numKeys: Long): 
RocksDBCheckpointMetadata = {
+val sstFiles = rocksDBFiles.collect { case file: RocksDBSstFile => file }
+val logFiles = rocksDBFiles.collect { case file: RocksDBLogFile => file }
+
+RocksDBCheckpointMetadata(sstFiles, logFiles, numKeys)
+  }
+}
+
+/**
+ * A RocksDBImmutableFile maintains a mapping between a local RocksDB file 
name and the name of
+ * its copy on DFS. Since these files are immutable, their DFS copies can be 
reused.

Review comment:
   Yes. Can be mapped to more than one local file but for different tasks. 
The most common scenario is task/stage retry.




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



[GitHub] [spark] xuanyuanking commented on a change in pull request #32272: [SPARK-35172][SS] The implementation of RocksDBCheckpointMetadata

2021-04-25 Thread GitBox


xuanyuanking commented on a change in pull request #32272:
URL: https://github.com/apache/spark/pull/32272#discussion_r619785921



##
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDBFileManager.scala
##
@@ -0,0 +1,165 @@
+/*
+ * 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.sql.execution.streaming.state
+
+import java.io.File
+import java.nio.charset.StandardCharsets.UTF_8
+import java.nio.file.Files
+
+import scala.collection.Seq
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include
+import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
+import com.fasterxml.jackson.module.scala.{DefaultScalaModule, 
ScalaObjectMapper}
+import org.json4s.NoTypeHints
+import org.json4s.jackson.Serialization
+
+/**
+ * Classes to represent metadata of checkpoints saved to DFS. Since this is 
converted to JSON, any
+ * changes to this MUST be backward-compatible.
+ */
+case class RocksDBCheckpointMetadata(
+sstFiles: Seq[RocksDBSstFile],
+logFiles: Seq[RocksDBLogFile],
+numKeys: Long) {
+  import RocksDBCheckpointMetadata._
+
+  def json: String = {
+// We turn this field into a null to avoid write a empty logFiles field in 
the json.
+val nullified = if (logFiles.isEmpty) this.copy(logFiles = null) else this

Review comment:
   It's related to the usage for RocksDB, we don't always have log files. 
But we must have sst files.




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