-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-28025][SS] Fix FileContextBasedCheckpointFileManager leaking crc files #25488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ import scala.language.implicitConversions | |
import org.scalatest.concurrent.Waiters._ | ||
import org.scalatest.time.SpanSugar._ | ||
|
||
import org.apache.spark.sql.internal.SQLConf | ||
import org.apache.spark.sql.test.SharedSparkSession | ||
import org.apache.spark.util.UninterruptibleThread | ||
|
||
|
@@ -58,6 +59,21 @@ class HDFSMetadataLogSuite extends SharedSparkSession { | |
} | ||
|
||
test("HDFSMetadataLog: purge") { | ||
testPurge() | ||
} | ||
|
||
Seq( | ||
classOf[FileSystemBasedCheckpointFileManager], | ||
classOf[FileContextBasedCheckpointFileManager] | ||
).map(_.getCanonicalName).foreach { cls => | ||
test(s"HDFSMetadataLog: purge - explicit file manager - $cls") { | ||
withSQLConf(SQLConf.STREAMING_CHECKPOINT_FILE_MANAGER_CLASS.parent.key -> cls) { | ||
testPurge() | ||
} | ||
} | ||
} | ||
|
||
private def testPurge(): Unit = { | ||
withTempDir { temp => | ||
val metadataLog = new HDFSMetadataLog[String](spark, temp.getAbsolutePath) | ||
assert(metadataLog.add(0, "batch0")) | ||
|
@@ -74,12 +90,16 @@ class HDFSMetadataLogSuite extends SharedSparkSession { | |
assert(metadataLog.get(2).isDefined) | ||
assert(metadataLog.getLatest().get._1 == 2) | ||
|
||
// There should be exactly one file, called "2", in the metadata directory. | ||
// There should be at most two files, called "2", and optionally crc file, | ||
// in the metadata directory. | ||
// This check also tests for regressions of SPARK-17475 | ||
val allFiles = new File(metadataLog.metadataPath.toString).listFiles() | ||
.filter(!_.getName.startsWith(".")).toSeq | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This filter broke the check of regression on SPARK-17475, hence regression came in. |
||
assert(allFiles.size == 1) | ||
assert(allFiles(0).getName() == "2") | ||
val allFiles = new File(metadataLog.metadataPath.toString).listFiles().toSeq | ||
assert(allFiles.size <= 2) | ||
assert(allFiles.exists(_.getName == "2")) | ||
if (allFiles.size == 2) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FileSystemBasedCheckpointFileManager is the case of crc file being left: it's not a leak because the origin file exists. It correctly deletes crc file when origin file is requested to be deleted, hence crc files for 0 and 1 don't exist. |
||
// there's possibly crc file being left as well | ||
assert(allFiles.exists(_.getName == ".2.crc")) | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ideal behavior would be renaming crc file to be matched with dstPath, but in SPARK-17475 seems like we just decided to remove the crc file, so I guess this is OK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to detect whether checksum is enabled? If it's disabled, we can save an
exists
call.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NVM. Just saw your latest comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, please feel free to let me know if we prefer alternative approach - I can make a change.