YARN-8194. Fixed reinitialization error for LinuxContainerExecutor.

Contributed by Chandni Singh
This commit is contained in:
Eric Yang 2018-05-02 20:07:19 -04:00
parent 6b63a0af9b
commit f4d280f02b
2 changed files with 39 additions and 34 deletions

View File

@ -20,6 +20,8 @@
import static org.apache.hadoop.fs.CreateFlag.CREATE;
import static org.apache.hadoop.fs.CreateFlag.OVERWRITE;
import org.apache.hadoop.yarn.server.nodemanager.executor.DeletionAsUserContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -844,6 +846,7 @@ public void cleanupContainer() throws IOException {
throw new IOException("Reap container failed for container "
+ containerIdStr);
}
cleanupContainerFiles(getContainerWorkDir());
}
/**
@ -1858,4 +1861,38 @@ private void recordContainerWorkDir(ContainerId containerId,
context.getNMStateStore().storeContainerWorkDir(containerId, workDir);
}
}
protected Path getContainerWorkDir() throws IOException {
String containerWorkDir = container.getWorkDir();
if (containerWorkDir == null
|| !dirsHandler.isGoodLocalDir(containerWorkDir)) {
throw new IOException(
"Could not find a good work dir " + containerWorkDir
+ " for container " + container);
}
return new Path(containerWorkDir);
}
/**
* Clean up container's files for container relaunch or cleanup.
*/
protected void cleanupContainerFiles(Path containerWorkDir) {
LOG.debug("cleanup container {} files", containerWorkDir);
// delete ContainerScriptPath
deleteAsUser(new Path(containerWorkDir, CONTAINER_SCRIPT));
// delete TokensPath
deleteAsUser(new Path(containerWorkDir, FINAL_CONTAINER_TOKENS_FILE));
}
private void deleteAsUser(Path path) {
try {
exec.deleteAsUser(new DeletionAsUserContext.Builder()
.setUser(container.getUser())
.setSubDir(path)
.build());
} catch (Exception e) {
LOG.warn("Failed to delete " + path, e);
}
}
}

View File

@ -34,7 +34,6 @@
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerExitEvent;
import org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.ContainerLocalizer;
import org.apache.hadoop.yarn.server.nodemanager.executor.ContainerStartContext;
import org.apache.hadoop.yarn.server.nodemanager.executor.DeletionAsUserContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -71,7 +70,8 @@ public Integer call() {
Path containerLogDir;
try {
Path containerWorkDir = getContainerWorkDir();
cleanupPreviousContainerFiles(containerWorkDir);
// Clean up container's previous files for container relaunch.
cleanupContainerFiles(containerWorkDir);
containerLogDir = getContainerLogDir();
@ -148,17 +148,6 @@ public Integer call() {
return ret;
}
private Path getContainerWorkDir() throws IOException {
String containerWorkDir = container.getWorkDir();
if (containerWorkDir == null
|| !dirsHandler.isGoodLocalDir(containerWorkDir)) {
throw new IOException(
"Could not find a good work dir " + containerWorkDir
+ " for container " + container);
}
return new Path(containerWorkDir);
}
private Path getContainerLogDir() throws IOException {
String containerLogDir = container.getLogDir();
@ -190,25 +179,4 @@ private Path getPidFilePath(String appIdStr,
return dirsHandler.getLocalPathForRead(
getPidFileSubpath(appIdStr, containerIdStr));
}
/**
* Clean up container's previous files for container relaunch.
*/
private void cleanupPreviousContainerFiles(Path containerWorkDir) {
// delete ContainerScriptPath
deleteAsUser(new Path(containerWorkDir, CONTAINER_SCRIPT));
// delete TokensPath
deleteAsUser(new Path(containerWorkDir, FINAL_CONTAINER_TOKENS_FILE));
}
private void deleteAsUser(Path path) {
try {
exec.deleteAsUser(new DeletionAsUserContext.Builder()
.setUser(container.getUser())
.setSubDir(path)
.build());
} catch (Exception e) {
LOG.warn("Failed to delete " + path, e);
}
}
}