@@ -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