From 8a1d7480f73906d8e0342690ec6c6b008d6de21b Mon Sep 17 00:00:00 2001 From: Karthik Kambatla Date: Fri, 14 Apr 2017 15:07:14 -0700 Subject: [PATCH] YARN-6433. Only accessible cgroup mount directories should be selected for a controller. (Miklos Szegedi via kasha) --- .../linux/resources/CGroupsHandlerImpl.java | 7 ++++++- .../linux/resources/TestCGroupsHandlerImpl.java | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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 0b29abc9a5..d5295c5cbe 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 @@ -236,7 +236,12 @@ private static String findControllerInMtab(String controller, Map> entries) { for (Map.Entry> e : entries.entrySet()) { if (e.getValue().contains(controller)) { - return e.getKey(); + if (new File(e.getKey()).canRead()) { + return e.getKey(); + } else { + LOG.warn(String.format( + "Skipping inaccessible cgroup mount point %s", e.getKey())); + } } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestCGroupsHandlerImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestCGroupsHandlerImpl.java index 38dc34fb78..4c0829efee 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestCGroupsHandlerImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestCGroupsHandlerImpl.java @@ -252,6 +252,10 @@ public static File createMockMTab(File parentDir) throws IOException { String cpuMtabContent = "none " + parentDir.getAbsolutePath() + "/cpu cgroup rw,relatime,cpu 0 0\n"; + // Mark an empty directory called 'cp' cgroup. It is processed before 'cpu' + String cpuMtabContentMissing = + "none " + parentDir.getAbsolutePath() + + "/cp cgroup rw,relatime,cpu 0 0\n"; String blkioMtabContent = "none " + parentDir.getAbsolutePath() + "/blkio cgroup rw,relatime,blkio 0 0\n"; @@ -264,6 +268,7 @@ public static File createMockMTab(File parentDir) throws IOException { } } FileWriter mtabWriter = new FileWriter(mockMtab.getAbsoluteFile()); + mtabWriter.write(cpuMtabContentMissing); mtabWriter.write(cpuMtabContent); mtabWriter.write(blkioMtabContent); mtabWriter.close();