Skip to content

Commit e8026f4

Browse files
author
Marcelo Vanzin
committed
Review feedback.
Use monotonic time, plus other stylistic things.
1 parent 49d2fd3 commit e8026f4

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

core/src/main/scala/org/apache/spark/deploy/history/FsHistoryProvider.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class FsHistoryProvider(conf: SparkConf) extends ApplicationHistoryProvider
3939
private val fs = Utils.getHadoopFileSystem(logDir)
4040

4141
// A timestamp of when the disk was last accessed to check for log updates
42-
private var lastLogCheckTime = -1L
42+
private var lastLogCheckTimeMs = -1L
4343

4444
// List of applications, in order from newest to oldest.
4545
private val appList = new AtomicReference[Seq[ApplicationHistoryInfo]](Nil)
@@ -55,13 +55,13 @@ class FsHistoryProvider(conf: SparkConf) extends ApplicationHistoryProvider
5555
private val logCheckingThread = new Thread("LogCheckingThread") {
5656
override def run() = Utils.logUncaughtExceptions {
5757
while (true) {
58-
val now = System.currentTimeMillis
59-
if (now - lastLogCheckTime > UPDATE_INTERVAL_MS) {
58+
val now = getMonotonicTime()
59+
if (now - lastLogCheckTimeMs > UPDATE_INTERVAL_MS) {
6060
Thread.sleep(UPDATE_INTERVAL_MS)
6161
} else {
6262
// If the user has manually checked for logs recently, wait until
6363
// UPDATE_INTERVAL_MS after the last check time
64-
Thread.sleep(lastLogCheckTime + UPDATE_INTERVAL_MS - now)
64+
Thread.sleep(lastLogCheckTimeMs + UPDATE_INTERVAL_MS - now)
6565
}
6666
checkForLogs()
6767
}
@@ -108,13 +108,12 @@ class FsHistoryProvider(conf: SparkConf) extends ApplicationHistoryProvider
108108
* applications that hasn't been updated since last time the logs were checked.
109109
*/
110110
def checkForLogs() = synchronized {
111-
lastLogCheckTime = System.currentTimeMillis
112-
logDebug("Checking for logs. Time is now %d.".format(lastLogCheckTime))
111+
lastLogCheckTimeMs = getMonotonicTime()
112+
logDebug("Checking for logs. Time is now %d.".format(lastLogCheckTimeMs))
113113
try {
114114
val logStatus = fs.listStatus(new Path(logDir))
115115
val logDirs = if (logStatus != null) logStatus.filter(_.isDir).toSeq else Seq[FileStatus]()
116116
val logInfos = logDirs
117-
.sortBy { dir => getModificationTime(dir) }
118117
.filter {
119118
dir => fs.isFile(new Path(dir.getPath(), EventLoggingListener.APPLICATION_COMPLETE))
120119
}
@@ -125,7 +124,7 @@ class FsHistoryProvider(conf: SparkConf) extends ApplicationHistoryProvider
125124
// For any application that either (i) is not listed or (ii) has changed since the last time
126125
// the listing was created (defined by the log dir's modification time), load the app's info.
127126
// Otherwise just reuse what's already in memory.
128-
val newApps = new mutable.ListBuffer[ApplicationHistoryInfo]
127+
val newApps = new mutable.ArrayBuffer[ApplicationHistoryInfo]
129128
for (dir <- logInfos) {
130129
val curr = currentApps.getOrElse(dir.getPath().getName(), null)
131130
if (curr == null || curr.lastUpdated < getModificationTime(dir)) {
@@ -198,4 +197,7 @@ class FsHistoryProvider(conf: SparkConf) extends ApplicationHistoryProvider
198197
}
199198
}
200199

200+
/** Returns the system's mononotically increasing time. */
201+
private def getMonotonicTime() = System.nanoTime() / (1000 * 1000)
202+
201203
}

core/src/main/scala/org/apache/spark/deploy/history/HistoryServer.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,13 @@ class HistoryServer(
5959
private val appLoader = new CacheLoader[String, SparkUI] {
6060
override def load(key: String): SparkUI = {
6161
val info = provider.getAppInfo(key)
62-
if (info != null) {
63-
info.ui.getSecurityManager.setUIAcls(uiAclsEnabled)
64-
info.ui.getSecurityManager.setViewAcls(info.sparkUser, info.viewAcls)
65-
attachSparkUI(info.ui)
66-
info.ui
67-
} else {
62+
if (info == null) {
6863
throw new NoSuchElementException()
6964
}
65+
info.ui.getSecurityManager.setUIAcls(uiAclsEnabled)
66+
info.ui.getSecurityManager.setViewAcls(info.sparkUser, info.viewAcls)
67+
attachSparkUI(info.ui)
68+
info.ui
7069
}
7170
}
7271

0 commit comments

Comments
 (0)