WweiL commented on code in PR #48355:
URL: https://github.com/apache/spark/pull/48355#discussion_r1866968399
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDBFileManager.scala:
##########
@@ -299,20 +313,33 @@ class RocksDBFileManager(
}
// Get latest snapshot version <= version
- def getLatestSnapshotVersion(version: Long): Long = {
+ def getLatestSnapshotVersionAndUniqueId(
+ version: Long, checkpointUniqueId: Option[String] = None): Array[(Long,
Option[String])] = {
val path = new Path(dfsRootDir)
if (fm.exists(path)) {
// If the latest version snapshot exists, we avoid listing.
- if (fm.exists(dfsBatchZipFile(version))) {
- return version
+ if (fm.exists(dfsBatchZipFile(version, checkpointUniqueId))) {
+ return Array((version, checkpointUniqueId))
+ } else if (fm.exists(dfsBatchZipFile(version))) {
+ // This is possible when the state was previously ran under checkpoint
format v1
+ // and restarted with v2. Then even if there is checkpointUniqueId
passed in, the file
+ // does not have that uniqueId in the filename.
+ return Array((version, None))
}
- fm.list(path, onlyZipFiles)
- .map(_.getPath.getName.stripSuffix(".zip"))
- .map(_.toLong)
- .filter(_ <= version)
- .foldLeft(0L)(math.max)
+ val versionAndUniqueIds = fm.list(path, onlyZipFiles)
+ .map(_.getPath.getName.stripSuffix(".zip").split("_"))
+ .filter {
+ case Array(ver, _) => ver.toLong <= version
+ case Array(ver) => ver.toLong <= version
+ }
+ .map {
+ case Array(version, uniqueId) => (version.toLong, Option(uniqueId))
+ case Array(version) => (version.toLong, None)
+ }
+ val maxVersion = versionAndUniqueIds.map(_._1).foldLeft(0L)(math.max)
+ versionAndUniqueIds.filter(_._1 == maxVersion)
Review Comment:
In fact the code does exactly what you say, not in this function but in here:
https://github.com/apache/spark/blob/473e0de8164e1ee68a811fea53acb71831b30340/sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDB.scala#L376-L380
Like I mentioned in the description and talked with you, this utility
function `getLatestSnapshotVersionAndUniqueId` merely returns the latest
<version, uniqueId> pair. This does not guarantee the returned pair is valid.
There could be more than one such pairs in case of task retry, and the part of
"finding the latest snapshot file that matches the checkpint Id from the
lineage" is done in the logic above.
Please let me know if there are more confusion.
--
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]