Github user jaceklaskowski commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13513#discussion_r65825474
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/FileStreamSource.scala
 ---
    @@ -129,3 +131,86 @@ class FileStreamSource(
     
       override def toString: String = s"FileStreamSource[$qualifiedBasePath]"
     }
    +
    +class FileStreamSourceLog(sparkSession: SparkSession, path: String)
    +  extends HDFSMetadataLog[Seq[String]](sparkSession, path) {
    +
    +  // Configurations about metadata compaction
    +  private val compactInterval = 
sparkSession.conf.get(SQLConf.FILE_SOURCE_LOG_COMPACT_INTERVAL)
    +  require(compactInterval > 0,
    +    s"Please set ${SQLConf.FILE_SOURCE_LOG_COMPACT_INTERVAL.key} (was 
$compactInterval) to a " +
    +      s"positive value.")
    +
    +  private val fileCleanupDelayMs = 
sparkSession.conf.get(SQLConf.FILE_SOURCE_LOG_CLEANUP_DELAY)
    +
    +  private val isDeletingExpiredLog = 
sparkSession.conf.get(SQLConf.FILE_SOURCE_LOG_DELETION)
    +
    +  private var compactBatchId: Long = -1L
    +
    +  private def isCompactionBatch(batchId: Long, compactInterval: Long): 
Boolean = {
    +    batchId % compactInterval == 0
    +  }
    +
    +  override def add(batchId: Long, metadata: Seq[String]): Boolean = {
    +    if (isCompactionBatch(batchId, compactInterval)) {
    +      compactMetadataLog(batchId - 1)
    +    }
    +
    +    super.add(batchId, metadata)
    +  }
    +
    +  private def compactMetadataLog(batchId: Long): Unit = {
    +    // read out compact metadata and merge with new metadata.
    +    val batches = super.get(Some(compactBatchId), Some(batchId))
    +    val totalMetadata = batches.flatMap(_._2)
    +    if (totalMetadata.isEmpty) {
    +      return
    +    }
    +
    +    // Remove old compact metadata file and rewrite.
    +    val renamedPath = new Path(path, 
s".${batchId.toString}-${UUID.randomUUID.toString}.tmp")
    +    fileManager.rename(batchIdToPath(batchId), renamedPath)
    +
    +    var isSuccess = false
    +    try {
    +      isSuccess = super.add(batchId, totalMetadata)
    +    } catch {
    +      case NonFatal(e) => isSuccess = false
    --- End diff --
    
    Why are you setting `isSuccess` to `false` since it's `false` already?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to