Skip to content

Commit 50eb4b9

Browse files
author
Marcelo Vanzin
committed
Review feedback.
1 parent c0e5ea5 commit 50eb4b9

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

core/src/main/scala/org/apache/spark/deploy/DeployMessage.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ private[deploy] object DeployMessages {
8888

8989
case class KillDriver(driverId: String) extends DeployMessage
9090

91+
case class ApplicationFinished(id: String)
92+
9193
// Worker internal
9294

9395
case object WorkDirCleanup // Sent to Worker actor periodically for cleaning up app folders
@@ -176,8 +178,4 @@ private[deploy] object DeployMessages {
176178

177179
case object SendHeartbeat
178180

179-
// Application finished message, used for cleanup
180-
181-
case class ApplicationFinished(id: String)
182-
183181
}

core/src/main/scala/org/apache/spark/deploy/worker/Worker.scala

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,15 @@ private[spark] class Worker(
342342
// Create local dirs for the executor. These are passed to the executor via the
343343
// SPARK_LOCAL_DIRS environment variable, and deleted by the Worker when the
344344
// application finishes.
345-
val appLocalDirs = appDirectories.get(appId).getOrElse {
346-
Utils.getOrCreateLocalRootDirs(conf).map { dir =>
347-
Utils.createDirectory(dir).getAbsolutePath()
348-
}.toSeq
345+
val appLocalDirs = appDirectories.synchronized {
346+
val dirs = appDirectories.get(appId).getOrElse {
347+
Utils.getOrCreateLocalRootDirs(conf).map { dir =>
348+
Utils.createDirectory(dir).getAbsolutePath()
349+
}.toSeq
350+
}
351+
appDirectories(appId) = dirs
352+
dirs
349353
}
350-
appDirectories(appId) = appLocalDirs
351354

352355
val manager = new ExecutorRunner(appId, execId, appDesc, cores_, memory_,
353356
self, workerId, host, sparkHome, executorDir, akkaUrl, conf, appLocalDirs,
@@ -469,13 +472,13 @@ private[spark] class Worker(
469472
registerWithMaster()
470473
}
471474

472-
private def maybeCleanupApplication(id: String): Unit = synchronized {
475+
private def maybeCleanupApplication(id: String): Unit = appDirectories.synchronized {
473476
val shouldCleanup = finishedApps.contains(id) && !executors.values.exists(_.appId == id)
474477
if (shouldCleanup) {
475478
finishedApps -= id
476-
appDirectories.remove(id).foreach {
479+
appDirectories.remove(id).foreach { dirList =>
477480
logInfo(s"Cleaning up local directories for application $id")
478-
_.foreach { dir =>
481+
dirList.foreach { dir =>
479482
Utils.deleteRecursively(new File(dir))
480483
}
481484
}

0 commit comments

Comments
 (0)