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

    https://github.com/apache/spark/pull/5491#discussion_r28712948
  
    --- Diff: 
core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala ---
    @@ -266,34 +268,38 @@ private[history] class FsHistoryProvider(conf: 
SparkConf) extends ApplicationHis
        */
       private def cleanLogs(): Unit = {
         try {
    -      val statusList = Option(fs.listStatus(new Path(logDir))).map(_.toSeq)
    -        .getOrElse(Seq[FileStatus]())
           val maxAge = 
conf.getTimeAsSeconds("spark.history.fs.cleaner.maxAge", "7d") * 1000
     
           val now = System.currentTimeMillis()
           val appsToRetain = new mutable.LinkedHashMap[String, 
FsApplicationHistoryInfo]()
     
    +      // Scan all logs from the log directory.
    +      // Only completed applications older than the specified max age will 
be deleted.
           applications.values.foreach { info =>
    -        if (now - info.lastUpdated <= maxAge) {
    +        if (now - info.lastUpdated <= maxAge || !info.completed) {
               appsToRetain += (info.id -> info)
    +        } else {
    +          appsToClean += info
             }
           }
     
           applications = appsToRetain
     
    -      // Scan all logs from the log directory.
    -      // Only directories older than the specified max age will be deleted
    -      statusList.foreach { dir =>
    +      val leftToClean = new mutable.ListBuffer[FsApplicationHistoryInfo]
    +      appsToClean.foreach { info =>
    --- End diff --
    
    Something like this would probably be more efficient:
    
        while (appsToClean.nonEmpty) {
          val info = appsToClean.last
          try {
            ...
            appsToClean.remove(appsToClean.size - 1)
          } catch {
            ...
          }
        }
    
    But probably not a big deal in this context.
    
    One thing to note is that if someone adds logs with the wrong permissions, 
this code will never be able to delete them, so those logs will forever be in 
the `appsToClean` list. It might be worth it to treat `AccessControlException` 
especially here and just give up trying to clean up logs with the wrong 
permissions.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to