Skip to content

Commit 1fe3936

Browse files
author
Robert Kruszewski
committed
Merge branch 'master' into rk/upstream
2 parents 2ca1ed9 + cb8d5cc commit 1fe3936

File tree

1 file changed

+26
-9
lines changed
  • resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn

1 file changed

+26
-9
lines changed

resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import java.io.{File, FileOutputStream, IOException, OutputStreamWriter}
2121
import java.net.{InetAddress, UnknownHostException, URI}
2222
import java.nio.ByteBuffer
2323
import java.nio.charset.StandardCharsets
24+
import java.security.PrivilegedExceptionAction
2425
import java.util.{Locale, Properties, UUID}
2526
import java.util.zip.{ZipEntry, ZipOutputStream}
2627

@@ -192,16 +193,32 @@ private[spark] class Client(
192193
* Cleanup application staging directory.
193194
*/
194195
private def cleanupStagingDir(appId: ApplicationId): Unit = {
195-
val stagingDirPath = new Path(appStagingBaseDir, getAppStagingDir(appId))
196-
try {
197-
val preserveFiles = sparkConf.get(PRESERVE_STAGING_FILES)
198-
val fs = stagingDirPath.getFileSystem(hadoopConf)
199-
if (!preserveFiles && fs.delete(stagingDirPath, true)) {
200-
logInfo(s"Deleted staging directory $stagingDirPath")
196+
if (sparkConf.get(PRESERVE_STAGING_FILES)) {
197+
return
198+
}
199+
200+
def cleanupStagingDirInternal(): Unit = {
201+
val stagingDirPath = new Path(appStagingBaseDir, getAppStagingDir(appId))
202+
try {
203+
val fs = stagingDirPath.getFileSystem(hadoopConf)
204+
if (fs.delete(stagingDirPath, true)) {
205+
logInfo(s"Deleted staging directory $stagingDirPath")
206+
}
207+
} catch {
208+
case ioe: IOException =>
209+
logWarning("Failed to cleanup staging dir " + stagingDirPath, ioe)
201210
}
202-
} catch {
203-
case ioe: IOException =>
204-
logWarning("Failed to cleanup staging dir " + stagingDirPath, ioe)
211+
}
212+
213+
if (isClusterMode && principal != null && keytab != null) {
214+
val newUgi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(principal, keytab)
215+
newUgi.doAs(new PrivilegedExceptionAction[Unit] {
216+
override def run(): Unit = {
217+
cleanupStagingDirInternal()
218+
}
219+
})
220+
} else {
221+
cleanupStagingDirInternal()
205222
}
206223
}
207224

0 commit comments

Comments
 (0)