chaoqin-li1123 commented on code in PR #41099:
URL: https://github.com/apache/spark/pull/41099#discussion_r1190235641
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDB.scala:
##########
@@ -334,25 +373,59 @@ class RocksDB(
loadedVersion = -1 // invalidate loaded version
throw t
} finally {
- if (rocksDBBackgroundThreadPaused) db.continueBackgroundWork()
- silentDeleteRecursively(checkpointDir, s"committing $newVersion")
// reset resources as either 1) we already pushed the changes and it has
been committed or
// 2) commit has failed and the current version is "invalidated".
release()
}
}
+ private def shouldCreateSnapshot(): Boolean = {
+ if (enableChangelogCheckpointing) {
+ assert(changelogWriter.isDefined)
+ val newVersion = loadedVersion + 1
+ newVersion - fileManager.getLastUploadedSnapshotVersion() >=
conf.minDeltasForSnapshot ||
+ changelogWriter.get.size > 1000
+ } else true
+ }
+
+ private def uploadSnapshot(): Unit = {
+ val localCheckpoint = synchronized {
+ val checkpoint = latestCheckpoint
+ latestCheckpoint = None
+ checkpoint
+ }
+ localCheckpoint match {
+ case Some(RocksDBCheckpoint(localDir, version, numKeys)) =>
+ try {
+ val uploadTime = timeTakenMs {
+ fileManager.saveCheckpointToDfs(localDir, version, numKeys)
+ fileManagerMetrics = fileManager.latestSaveCheckpointMetrics
+ }
+ logInfo(s"Upload snapshot of version $version, time taken:
$uploadTime ms")
+ } finally {
+ localCheckpoint.foreach(_.close())
+ }
+ case _ =>
+ }
+ }
+
/**
* Drop uncommitted changes, and roll back to previous version.
*/
def rollback(): Unit = {
numKeysOnWritingVersion = numKeysOnLoadedVersion
loadedVersion = -1L
+ changelogWriter.foreach(_.abort())
+ // Make sure changelogWriter gets recreated next time.
+ changelogWriter = None
release()
logInfo(s"Rolled back to $loadedVersion")
}
def cleanup(): Unit = {
+ if (enableChangelogCheckpointing) {
+ uploadSnapshot()
+ }
Review Comment:
We can call it doMaintenance()
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]