YARN-7848 Force removal of docker containers that do not get removed on first try. Contributed by Eric Yang

This commit is contained in:
Eric Badger 2019-04-15 20:47:09 +00:00
parent 62e38ea911
commit 5583e1b6fc
3 changed files with 21 additions and 10 deletions

View File

@ -3206,12 +3206,15 @@ int remove_docker_container(char**argv, int argc) {
const char *container_id = NULL;
int start_index = 0;
char **args = alloc_and_clear_memory(argc + 1, sizeof(char *));
args[0] = "-f";
if (argc == 2) {
yarn_hierarchy = argv[0];
container_id = argv[1];
// Skip the yarn_hierarchy argument for exec_docker_command
start_index = 1;
}
args[1] = argv[start_index];
pid_t child_pid = fork();
if (child_pid == -1) {
@ -3222,15 +3225,15 @@ int remove_docker_container(char**argv, int argc) {
}
if (child_pid == 0) { // child
int rc = exec_docker_command("rm", argv + start_index, argc - start_index);
return rc; // Only get here if exec fails
int rc = exec_docker_command("rm", args, 2);
exit_code = rc; // Only get here if exec fails
} else { // parent
exit_code = wait_and_get_exit_code(child_pid);
if (exit_code != 0) {
exit_code = DOCKER_RUN_FAILED;
}
}
free(args);
// Clean up cgroups if necessary
if (yarn_hierarchy != NULL) {

View File

@ -722,11 +722,19 @@ int get_docker_rm_command(const char *command_file, const struct configuration *
}
ret = add_to_args(args, DOCKER_RM_COMMAND);
if (ret == 0) {
ret = add_to_args(args, container_name);
if (ret != 0) {
ret = BUFFER_TOO_SMALL;
}
if (ret != 0) {
ret = BUFFER_TOO_SMALL;
goto free_and_exit;
}
ret = add_to_args(args, "-f");
if (ret != 0) {
ret = BUFFER_TOO_SMALL;
goto free_and_exit;
}
ret = add_to_args(args, container_name);
if (ret != 0) {
ret = BUFFER_TOO_SMALL;
goto free_and_exit;
}
free_and_exit:
free(container_name);

View File

@ -304,7 +304,7 @@ namespace ContainerExecutor {
file_cmd_vec.push_back(
std::make_pair<std::string, std::string>(
"[docker-command-execution]\n docker-command=rm\n name=container_e1_12312_11111_02_000001",
"rm container_e1_12312_11111_02_000001"));
"rm -f container_e1_12312_11111_02_000001"));
std::vector<std::pair<std::string, int> > bad_file_cmd_vec;
bad_file_cmd_vec.push_back(std::make_pair<std::string, int>(
@ -1711,7 +1711,7 @@ namespace ContainerExecutor {
"/usr/bin/docker --config=/my-config pull image-id"));
input_output_map.push_back(std::make_pair<std::string, std::string>(
"[docker-command-execution]\n docker-command=rm\n docker-config=/my-config\n name=container_e1_12312_11111_02_000001",
"/usr/bin/docker --config=/my-config rm container_e1_12312_11111_02_000001"));
"/usr/bin/docker --config=/my-config rm -f container_e1_12312_11111_02_000001"));
input_output_map.push_back(std::make_pair<std::string, std::string>(
"[docker-command-execution]\n docker-command=stop\n docker-config=/my-config\n name=container_e1_12312_11111_02_000001",
"/usr/bin/docker --config=/my-config stop container_e1_12312_11111_02_000001"));