Github user vanzin commented on a diff in the pull request:
https://github.com/apache/spark/pull/5491#discussion_r28347842
--- Diff:
core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala ---
@@ -273,33 +273,32 @@ 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.getLong("spark.history.fs.cleaner.maxAge.seconds",
DEFAULT_SPARK_HISTORY_FS_MAXAGE_S) * 1000
val now = System.currentTimeMillis()
val appsToRetain = new mutable.LinkedHashMap[String,
FsApplicationHistoryInfo]()
+ val appsToClean = 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.id -> info)
}
}
applications = appsToRetain
- // Scan all logs from the log directory.
- // Only directories older than the specified max age will be deleted
- statusList.foreach { dir =>
+ appsToClean.values.foreach { info =>
try {
- if (now - dir.getModificationTime() > maxAge) {
- // if path is a directory and set to true,
- // the directory is deleted else throws an exception
- fs.delete(dir.getPath, true)
- }
+ fs.delete(new Path(logDir + "/" + info.logPath), true)
} catch {
- case t: IOException => logError(s"IOException in cleaning logs
of $dir", t)
+ case t: IOException =>
+ logError(s"IOException in cleaning logs of ${info.logPath}", t)
+ applications += (info.id -> info)
--- End diff --
No, you don't want to modify `applications` like this because then the code
is not thread-safe. The only modification you can make to `applications` is to
set it to a different map.
Also, by doing this, the app would be inserted in the map in, potentially,
the wrong order.
---
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]