zsxwing commented on a change in pull request #24186: [SPARK-27254][SS] Cleanup
complete but invalid output files in ManifestFileCommitProtocol if job is
aborted
URL: https://github.com/apache/spark/pull/24186#discussion_r328856335
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/streaming/FileStreamSinkSuite.scala
##########
@@ -473,6 +476,73 @@ abstract class FileStreamSinkSuite extends StreamTest {
assert(outputFiles.toList.isEmpty, "Incomplete files should be cleaned
up.")
}
}
+
+ testQuietly("cleanup complete but invalid output for aborted job") {
+ withSQLConf(("spark.sql.streaming.commitProtocolClass",
+
classOf[PendingCommitFilesTrackingManifestFileCommitProtocol].getCanonicalName))
{
+ withTempDir { tempDir =>
+ val checkpointDir = new File(tempDir, "chk")
+ val outputDir = new File(tempDir, "output @#output")
+ val inputData = MemoryStream[Int]
+ inputData.addData(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
+ val q = inputData.toDS()
+ .repartition(10)
+ .map { value =>
+ // we intend task failure after some tasks succeeds
+ if (value == 5) {
+ // put some delay to let other task commits before this task
fails
+ Thread.sleep(100)
+ value / 0
+ } else {
+ value
+ }
+ }
+ .writeStream
+ .option("checkpointLocation", checkpointDir.getCanonicalPath)
+ .format("parquet")
+ .start(outputDir.getCanonicalPath)
+
+ intercept[StreamingQueryException] {
+ try {
+ q.processAllAvailable()
+ } finally {
+ q.stop()
+ }
+ }
+
+ import PendingCommitFilesTrackingManifestFileCommitProtocol._
+ val outputFiles = Files.walk(outputDir.toPath).iterator().asScala
+ .filter(_.toString.endsWith(".parquet"))
+ // there would be possible to have race condition:
+ // - some tasks complete while abortJob is being called
+ // we can't delete complete files for these tasks (it's OK since this
is a best effort)
+ assert(!outputFiles.toList.exists(f =>
tracking.contains(f.toUri.getPath)),
Review comment:
Nit: Not sure if the APIs we are using here will generate the same file path
or not on all operator systems. Maybe just check the file names?
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]