Github user andrewor14 commented on a diff in the pull request:
https://github.com/apache/spark/pull/4214#discussion_r25109806
--- Diff:
core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala ---
@@ -230,6 +250,45 @@ private[history] class FsHistoryProvider(conf:
SparkConf) extends ApplicationHis
}
/**
+ * Delete event logs from the log directory according to the clean
policy defined by the user.
+ */
+ private def cleanLogs() = {
+ 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 newApps = new mutable.LinkedHashMap[String,
FsApplicationHistoryInfo]()
+ def addIfNotExpire(info: FsApplicationHistoryInfo) = {
+ if (now - info.lastUpdated <= maxAge) {
+ newApps += (info.id -> info)
+ }
+ }
+
+ val oldIterator = applications.values.iterator.buffered
+ oldIterator.foreach(addIfNotExpire)
--- End diff --
what's the point of (1) storing it in a variable here if we just use it
right away, (2) using a buffered iterator, and (3) defining `addIfNotExpired`?
I think we can just do
```
// Retain applications that have not expired
applications.values.foreach {
if (now - info.lastUpdated <= maxAge) {
newApps += (info.id -> info)
}
}
```
I believe this change simplifies the code without sacrificing any
readability
---
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]