You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/01/16 01:06:20 UTC

[GitHub] zsxwing commented on a change in pull request #22952: [SPARK-20568][SS] Provide option to clean up completed files in streaming query

zsxwing commented on a change in pull request #22952: [SPARK-20568][SS] Provide option to clean up completed files in streaming query
URL: https://github.com/apache/spark/pull/22952#discussion_r238901099
 
 

 ##########
 File path: sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/FileStreamSource.scala
 ##########
 @@ -257,16 +297,64 @@ class FileStreamSource(
    * equal to `end` and will only request offsets greater than `end` in the future.
    */
   override def commit(end: Offset): Unit = {
-    // No-op for now; FileStreamSource currently garbage-collects files based on timestamp
-    // and the value of the maxFileAge parameter.
+    def move(entry: FileEntry, baseArchiveDirPath: String): Unit = {
+      val curPath = new Path(new URI(entry.path))
+      val curPathUri = curPath.toUri
+
+      val newPath = new Path(baseArchiveDirPath + curPathUri.getPath)
+      try {
+        logDebug(s"Creating directory if it doesn't exist ${newPath.getParent}")
+        if (!fs.exists(newPath.getParent)) {
+          fs.mkdirs(newPath.getParent)
+        }
+
+        logDebug(s"Archiving completed file $curPath to $newPath")
+        if (!fs.rename(curPath, newPath)) {
+          // Log to warning but swallow exception to avoid process being stopped
+          logWarning(s"Fail to move $curPath to $newPath / skip moving file.")
+        }
+      } catch {
+        case NonFatal(e) =>
+          // Log to warning but swallow exception to avoid process being stopped
+          logWarning(s"Fail to move $curPath to $newPath / skip moving file.", e)
+      }
+    }
+
+    def remove(entry: FileEntry): Unit = {
+      val curPath = new Path(new URI(entry.path))
+      try {
+        logDebug(s"Removing completed file $curPath")
+        fs.delete(curPath, false)
+      } catch {
+        case NonFatal(e) =>
+          // Log to error but swallow exception to avoid process being stopped
+          logWarning(s"Fail to remove $curPath / skip removing file.", e)
+      }
+    }
+
+    val logOffset = FileStreamSourceOffset(end).logOffset
+    val files = metadataLog.get(Some(logOffset), Some(logOffset)).flatMap(_._2)
 
 Review comment:
   Could you avoid these extra reading when `cleanSource` is `no_op`?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org