YARN-8587. Added retries for fetching docker exit code.

Contributed by Charo Zhang

(cherry picked from commit c16c49b8c3b8e2e42c00e79a50e7ae029ebe98e2)
This commit is contained in:
Eric Yang 2018-10-24 17:28:23 -04:00
parent 68a98be8a2
commit 8b228a42e9

View File

@ -1765,20 +1765,22 @@ int launch_docker_container_as_user(const char * user, const char *app_id,
docker_binary, container_id); docker_binary, container_id);
fprintf(LOGFILE, "Obtaining the exit code...\n"); fprintf(LOGFILE, "Obtaining the exit code...\n");
fprintf(LOGFILE, "Docker inspect command: %s\n", docker_inspect_exitcode_command); fprintf(LOGFILE, "Docker inspect command: %s\n", docker_inspect_exitcode_command);
FILE* inspect_exitcode_docker = popen(docker_inspect_exitcode_command, "r"); int count = 0;
if(inspect_exitcode_docker == NULL) { int max_retries = get_max_retries(&CFG);
fprintf(ERRORFILE, "Done with inspect_exitcode, inspect_exitcode_docker is null\n"); while (count < max_retries) {
fflush(ERRORFILE); FILE* inspect_exitcode_docker = popen(docker_inspect_exitcode_command, "r");
exit_code = -1; res = fscanf (inspect_exitcode_docker, "%d", &exit_code);
goto cleanup; if (pclose (inspect_exitcode_docker) != 0 || res <= 0) {
} fprintf (ERRORFILE, "Could not inspect docker to get Exit code %s.\n", docker_inspect_exitcode_command);
res = fscanf (inspect_exitcode_docker, "%d", &exit_code); fflush(ERRORFILE);
if (pclose (inspect_exitcode_docker) != 0 || res <= 0) { exit_code = -1;
fprintf (ERRORFILE, } else {
"Could not inspect docker to get exitcode: %s.\n", docker_inspect_exitcode_command); if (exit_code != 0) {
fflush(ERRORFILE); break;
exit_code = -1; }
goto cleanup; }
sleep(3);
count++;
} }
fprintf(LOGFILE, "Exit code from docker inspect: %d\n", exit_code); fprintf(LOGFILE, "Exit code from docker inspect: %d\n", exit_code);
@ -2708,4 +2710,4 @@ int remove_docker_container(char**argv, int argc) {
exit_code = clean_docker_cgroups(yarn_hierarchy, container_id); exit_code = clean_docker_cgroups(yarn_hierarchy, container_id);
} }
return exit_code; return exit_code;
} }