From d4258fcad71eabe2de3cf829cde36840200ab9b6 Mon Sep 17 00:00:00 2001 From: Wangda Tan Date: Tue, 7 Aug 2018 12:36:55 -0700 Subject: [PATCH] YARN-8629. Container cleanup fails while trying to delete Cgroups. (Suma Shivaprasad via wangda) Change-Id: I392ef4f8baa84d5d7b1f2e438c560b5426b6d4f2 --- .../linux/resources/CGroupsHandlerImpl.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/CGroupsHandlerImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/CGroupsHandlerImpl.java index c3800b6e4d..a547e8fd9f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/CGroupsHandlerImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/CGroupsHandlerImpl.java @@ -504,23 +504,29 @@ private void logLineFromTasksFile(File cgf) { private boolean checkAndDeleteCgroup(File cgf) throws InterruptedException { boolean deleted = false; // FileInputStream in = null; - try (FileInputStream in = new FileInputStream(cgf + "/tasks")) { - if (in.read() == -1) { + if ( cgf.exists() ) { + try (FileInputStream in = new FileInputStream(cgf + "/tasks")) { + if (in.read() == -1) { /* * "tasks" file is empty, sleep a bit more and then try to delete the * cgroup. Some versions of linux will occasionally panic due to a race * condition in this area, hence the paranoia. */ - Thread.sleep(deleteCGroupDelay); - deleted = cgf.delete(); - if (!deleted) { - LOG.warn("Failed attempt to delete cgroup: " + cgf); + Thread.sleep(deleteCGroupDelay); + deleted = cgf.delete(); + if (!deleted) { + LOG.warn("Failed attempt to delete cgroup: " + cgf); + } + } else{ + logLineFromTasksFile(cgf); } - } else { - logLineFromTasksFile(cgf); + } catch (IOException e) { + LOG.warn("Failed to read cgroup tasks file. ", e); } - } catch (IOException e) { - LOG.warn("Failed to read cgroup tasks file. ", e); + } else { + LOG.info("Parent Cgroups directory {} does not exist. Skipping " + + "deletion", cgf.getPath()); + deleted = true; } return deleted; }