Fix ContainerLocalizer permission bug by also deleting filecache folder

Signed-off-by: Shanyu Zhao <shzhao@microsoft.com>
This commit is contained in:
Shanyu Zhao 2019-11-27 16:42:23 -08:00
parent 29242a6a7a
commit beca49dfbf
1 changed files with 26 additions and 18 deletions

View File

@ -316,30 +316,38 @@ public class SecureModeLocalUserAllocator {
String localUser = appUserToLocalUser.remove(appUser).localUser;
allocated.set(localUserInfo.localUserIndex, false);
if (delService != null) {
// check if node manager usercache/<appUser>/appcache folder exists
// check and delete these node manager folders, which will cause permission issues later:
// usercache/<appUser>/appcache
// usercache/<appUser>/filecche
for (String localDir : nmLocalDirs) {
Path usersDir = new Path(localDir, ContainerLocalizer.USERCACHE);
Path userDir = new Path(usersDir, appUser);
Path userAppCacheDir = new Path(userDir, ContainerLocalizer.APPCACHE);
FileStatus status;
Path userFileCacheDir = new Path(userDir, ContainerLocalizer.FILECACHE);
ArrayList<Path> toDelete = new ArrayList<Path>();
toDelete.add(userAppCacheDir);
toDelete.add(userFileCacheDir);
for (Path dir : toDelete) {
FileStatus status = null;
try {
status = lfs.getFileStatus(userAppCacheDir);
}
catch(FileNotFoundException fs) {
status = null;
}
catch(IOException ie) {
String msg = "Could not get file status for local dir " + userDir;
String msg = "Could not get file status for local dir " + dir;
LOG.warn(msg, ie);
throw new YarnRuntimeException(msg, ie);
}
if (status != null) {
FileDeletionTask delTask = new FileDeletionTask(delService, localUser,
userAppCacheDir, null);
dir, null);
delService.delete(delTask);
}
}
}
}
LOG.info("Deallocated local user index " + localUserInfo.localUserIndex +
" for appUser " + appUser);
}