Skip to content

Commit f61071b

Browse files
committed
Fixed cleanup problem
1 parent 14502d5 commit f61071b

File tree

1 file changed

+23
-2
lines changed
  • yarn/src/main/scala/org/apache/spark/deploy/yarn

1 file changed

+23
-2
lines changed

yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.apache.spark.deploy.yarn
1919

20-
import java.io.{ByteArrayInputStream, DataInputStream, File, FileOutputStream}
20+
import java.io.{ByteArrayInputStream, DataInputStream, File, FileOutputStream, IOException}
2121
import java.net.{InetAddress, UnknownHostException, URI, URISyntaxException}
2222
import java.nio.ByteBuffer
2323
import java.security.PrivilegedExceptionAction
@@ -515,7 +515,28 @@ private[spark] class Client(
515515
logInfo("Setting up container launch context for our AM")
516516
val appId = newAppResponse.getApplicationId
517517
val appStagingDir = getAppStagingDir(appId)
518-
val localResources = prepareLocalResources(appStagingDir)
518+
var localResources: Map[String, LocalResource] = null
519+
try {
520+
localResources = prepareLocalResources(appStagingDir)
521+
} catch {
522+
case e: Throwable =>
523+
var stagingDirPath: Path = null
524+
try {
525+
val preserveFiles = sparkConf.getBoolean("spark.yarn.preserve.staging.files", false)
526+
if (!preserveFiles) {
527+
stagingDirPath = new Path(appStagingDir)
528+
logInfo("Deleting staging directory " + stagingDirPath)
529+
val fs = FileSystem.get(hadoopConf)
530+
fs.delete(stagingDirPath, true)
531+
}
532+
} catch {
533+
case ioe: IOException =>
534+
logError("Failed to cleanup staging dir " + stagingDirPath, ioe)
535+
} finally {
536+
throw e
537+
}
538+
}
539+
519540
val launchEnv = setupLaunchEnv(appStagingDir)
520541
val amContainer = Records.newRecord(classOf[ContainerLaunchContext])
521542
amContainer.setLocalResources(localResources)

0 commit comments

Comments
 (0)