From 543bd9faa54b93b46108158d5e3730ba54fe163e Mon Sep 17 00:00:00 2001 From: Peter Szucs Date: Mon, 13 May 2024 11:56:39 +0200 Subject: [PATCH 1/6] YARN-11692. Support mixed cgroup v1/v2 controller structure Change-Id: I10a024b3fa88aaeb5dfcd9173f53200b00ccc7df --- .../resources/ResourceHandlerModule.java | 91 +++++++++++++------ .../resources/TestResourceHandlerModule.java | 38 +------- 2 files changed, 65 insertions(+), 64 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/ResourceHandlerModule.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/ResourceHandlerModule.java index 118013f55a14b..5581db72305c6 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/ResourceHandlerModule.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/ResourceHandlerModule.java @@ -63,11 +63,12 @@ public class ResourceHandlerModule { * as resource metrics functionality. We need to ensure that the same * instance is used for both. */ + private static volatile CGroupsHandler cGroupsV1Handler; + private static volatile CGroupsHandler cGroupsV2Handler; private static volatile TrafficControlBandwidthHandlerImpl trafficControlBandwidthHandler; private static volatile NetworkPacketTaggingHandlerImpl networkPacketTaggingHandlerImpl; - private static volatile CGroupsHandler cGroupsHandler; private static volatile CGroupsBlkioResourceHandlerImpl cGroupsBlkioResourceHandler; private static volatile MemoryResourceHandler @@ -75,23 +76,41 @@ public class ResourceHandlerModule { private static volatile CpuResourceHandler cGroupsCpuResourceHandler; - /** - * Returns an initialized, thread-safe CGroupsHandler instance. - */ - private static CGroupsHandler getInitializedCGroupsHandler(Configuration conf) + private static void initializeCGroupsHandlers(Configuration conf) throws ResourceHandlerException { + initializeCGroupsV1Handler(conf); + if (cgroupsV2Enabled) { + initializeCGroupsV2Handler(conf); + } + } + + private static void initializeCGroupsV1Handler(Configuration conf) throws ResourceHandlerException { - if (cGroupsHandler == null) { + if (cGroupsV1Handler == null) { synchronized (CGroupsHandler.class) { - if (cGroupsHandler == null) { - cGroupsHandler = cgroupsV2Enabled - ? new CGroupsV2HandlerImpl(conf, PrivilegedOperationExecutor.getInstance(conf)) - : new CGroupsHandlerImpl(conf, PrivilegedOperationExecutor.getInstance(conf)); - LOG.debug("Value of CGroupsHandler is: {}", cGroupsHandler); + if (cGroupsV1Handler == null) { + cGroupsV1Handler = new CGroupsHandlerImpl( + conf, PrivilegedOperationExecutor.getInstance(conf)); + LOG.debug("Value of CGroupsV1Handler is: {}", cGroupsV1Handler); } } } + } - return cGroupsHandler; + private static void initializeCGroupsV2Handler(Configuration conf) + throws ResourceHandlerException { + if (cGroupsV2Handler == null) { + synchronized (CGroupsHandler.class) { + if (cGroupsV2Handler == null) { + cGroupsV2Handler = new CGroupsV2HandlerImpl( + conf, PrivilegedOperationExecutor.getInstance(conf)); + LOG.debug("Value of CGroupsV2Handler is: {}", cGroupsV2Handler); + } + } + } + } + + private static boolean isMountedInCGroupsV2(CGroupsHandler.CGroupController controller) { + return (cGroupsV2Handler != null && cGroupsV2Handler.getControllerPath(controller) != null); } /** @@ -101,7 +120,7 @@ private static CGroupsHandler getInitializedCGroupsHandler(Configuration conf) */ public static CGroupsHandler getCGroupsHandler() { - return cGroupsHandler; + return cgroupsV2Enabled ? cGroupsV2Handler : cGroupsV1Handler; } /** @@ -109,10 +128,10 @@ public static CGroupsHandler getCGroupsHandler() { * not initialized, or if the path is empty. */ public static String getCgroupsRelativeRoot() { - if (cGroupsHandler == null) { + if (getCGroupsHandler() == null) { return null; } - String cGroupPath = cGroupsHandler.getRelativePathForCGroup(""); + String cGroupPath = getCGroupsHandler().getRelativePathForCGroup(""); if (cGroupPath == null || cGroupPath.isEmpty()) { return null; } @@ -153,9 +172,13 @@ private static CpuResourceHandler initCGroupsCpuResourceHandler( synchronized (CpuResourceHandler.class) { if (cGroupsCpuResourceHandler == null) { LOG.debug("Creating new cgroups cpu handler"); - cGroupsCpuResourceHandler = cgroupsV2Enabled - ? new CGroupsV2CpuResourceHandlerImpl(getInitializedCGroupsHandler(conf)) - : new CGroupsCpuResourceHandlerImpl(getInitializedCGroupsHandler(conf)); + + initializeCGroupsHandlers(conf); + if (isMountedInCGroupsV2(CGroupsHandler.CGroupController.CPU)) { + cGroupsCpuResourceHandler = new CGroupsV2CpuResourceHandlerImpl(cGroupsV2Handler); + } else { + cGroupsCpuResourceHandler = new CGroupsCpuResourceHandlerImpl(cGroupsV1Handler); + } return cGroupsCpuResourceHandler; } } @@ -173,9 +196,11 @@ private static CpuResourceHandler initCGroupsCpuResourceHandler( synchronized (OutboundBandwidthResourceHandler.class) { if (trafficControlBandwidthHandler == null) { LOG.info("Creating new traffic control bandwidth handler."); + + initializeCGroupsHandlers(conf); trafficControlBandwidthHandler = new TrafficControlBandwidthHandlerImpl(PrivilegedOperationExecutor - .getInstance(conf), getInitializedCGroupsHandler(conf), + .getInstance(conf), cGroupsV1Handler, new TrafficController(conf, PrivilegedOperationExecutor .getInstance(conf))); } @@ -208,10 +233,11 @@ public static ResourceHandler getNetworkTaggingHandler(Configuration conf) synchronized (OutboundBandwidthResourceHandler.class) { if (networkPacketTaggingHandlerImpl == null) { LOG.info("Creating new network-tagging-handler."); + + initializeCGroupsHandlers(conf); networkPacketTaggingHandlerImpl = new NetworkPacketTaggingHandlerImpl( - PrivilegedOperationExecutor.getInstance(conf), - getInitializedCGroupsHandler(conf)); + PrivilegedOperationExecutor.getInstance(conf), cGroupsV1Handler); } } } @@ -239,9 +265,10 @@ private static CGroupsBlkioResourceHandlerImpl getCgroupsBlkioResourceHandler( synchronized (DiskResourceHandler.class) { if (cGroupsBlkioResourceHandler == null) { LOG.debug("Creating new cgroups blkio handler"); + + initializeCGroupsHandlers(conf); cGroupsBlkioResourceHandler = - new CGroupsBlkioResourceHandlerImpl( - getInitializedCGroupsHandler(conf)); + new CGroupsBlkioResourceHandlerImpl(cGroupsV1Handler); } } } @@ -263,9 +290,13 @@ public static MemoryResourceHandler initMemoryResourceHandler( if (cGroupsMemoryResourceHandler == null) { synchronized (MemoryResourceHandler.class) { if (cGroupsMemoryResourceHandler == null) { - cGroupsMemoryResourceHandler = cgroupsV2Enabled - ? new CGroupsV2MemoryResourceHandlerImpl(getInitializedCGroupsHandler(conf)) - : new CGroupsMemoryResourceHandlerImpl(getInitializedCGroupsHandler(conf)); + + initializeCGroupsHandlers(conf); + if (isMountedInCGroupsV2(CGroupsHandler.CGroupController.MEMORY)) { + cGroupsMemoryResourceHandler = new CGroupsV2MemoryResourceHandlerImpl(cGroupsV2Handler); + } else { + cGroupsMemoryResourceHandler = new CGroupsMemoryResourceHandlerImpl(cGroupsV1Handler); + } } } } @@ -327,9 +358,10 @@ private static void addHandlersFromConfiguredResourcePlugins( } for (ResourcePlugin plugin : pluginMap.values()) { + initializeCGroupsHandlers(conf); addHandlerIfNotNull(handlerList, plugin.createResourceHandler(nmContext, - getInitializedCGroupsHandler(conf), + cGroupsV1Handler, PrivilegedOperationExecutor.getInstance(conf))); } } @@ -361,8 +393,9 @@ static void nullifyResourceHandlerChain() throws ResourceHandlerException { } @VisibleForTesting - static void resetCgroupsHandler() { - cGroupsHandler = null; + static void resetCGroupsHandlers() { + cGroupsV1Handler = null; + cGroupsV2Handler = null; } @VisibleForTesting 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/TestResourceHandlerModule.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/TestResourceHandlerModule.java index 9104defb92ae4..dc543346d5298 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/TestResourceHandlerModule.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/TestResourceHandlerModule.java @@ -49,7 +49,7 @@ public void setup() throws Exception { networkEnabledConf.setBoolean(YarnConfiguration.NM_NETWORK_RESOURCE_ENABLED, true); ResourceHandlerModule.nullifyResourceHandlerChain(); - ResourceHandlerModule.resetCgroupsHandler(); + ResourceHandlerModule.resetCGroupsHandlers(); ResourceHandlerModule.resetCpuResourceHandler(); ResourceHandlerModule.resetMemoryResourceHandler(); } @@ -116,57 +116,25 @@ public void testDiskResourceHandler() throws Exception { } @Test - public void testCpuResourceHandlerClassForCgroupV1() throws ResourceHandlerException { - Configuration conf = new YarnConfiguration(); - conf.setBoolean(YarnConfiguration.NM_CPU_RESOURCE_ENABLED, true); - conf.setBoolean(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_V2_ENABLED, false); - - initResourceHandlerChain(conf); - - Assert.assertTrue(ResourceHandlerModule.getCpuResourceHandler() - instanceof CGroupsCpuResourceHandlerImpl); - Assert.assertTrue(ResourceHandlerModule.getCGroupsHandler() - instanceof CGroupsHandlerImpl); - } - - @Test - public void testCpuResourceHandlerClassForCgroupV2() throws ResourceHandlerException { - Configuration conf = new YarnConfiguration(); - conf.setBoolean(YarnConfiguration.NM_CPU_RESOURCE_ENABLED, true); - conf.setBoolean(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_V2_ENABLED, true); - - initResourceHandlerChain(conf); - - Assert.assertTrue(ResourceHandlerModule.getCpuResourceHandler() - instanceof CGroupsV2CpuResourceHandlerImpl); - Assert.assertTrue(ResourceHandlerModule.getCGroupsHandler() - instanceof CGroupsV2HandlerImpl); - } - - @Test - public void testMemoryResourceHandlerClassForCgroupV1() throws ResourceHandlerException { + public void testCgroupsHandlerClassForCgroupV1() throws ResourceHandlerException { Configuration conf = new YarnConfiguration(); conf.setBoolean(YarnConfiguration.NM_MEMORY_RESOURCE_ENABLED, true); conf.setBoolean(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_V2_ENABLED, false); initResourceHandlerChain(conf); - Assert.assertTrue(ResourceHandlerModule.getMemoryResourceHandler() - instanceof CGroupsMemoryResourceHandlerImpl); Assert.assertTrue(ResourceHandlerModule.getCGroupsHandler() instanceof CGroupsHandlerImpl); } @Test - public void testMemoryResourceHandlerClassForCgroupV2() throws ResourceHandlerException { + public void testCgroupsHandlerClassForCgroupV2() throws ResourceHandlerException { Configuration conf = new YarnConfiguration(); conf.setBoolean(YarnConfiguration.NM_MEMORY_RESOURCE_ENABLED, true); conf.setBoolean(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_V2_ENABLED, true); initResourceHandlerChain(conf); - Assert.assertTrue(ResourceHandlerModule.getMemoryResourceHandler() - instanceof CGroupsV2MemoryResourceHandlerImpl); Assert.assertTrue(ResourceHandlerModule.getCGroupsHandler() instanceof CGroupsV2HandlerImpl); } From 280cac08b178d8b844f9309c6ad16d7f868320e6 Mon Sep 17 00:00:00 2001 From: Peter Szucs Date: Mon, 13 May 2024 14:47:10 +0200 Subject: [PATCH 2/6] YARN-11692. Added a new config for cgroups v2 mount path Change-Id: I1de48e26ce0f827be16a7c435f240c14487d2baa --- .../apache/hadoop/yarn/conf/YarnConfiguration.java | 4 ++++ .../src/main/resources/yarn-default.xml | 14 ++++++++++++++ .../linux/resources/CGroupsMountConfig.java | 13 ++++++++++++- .../linux/resources/CGroupsV2HandlerImpl.java | 4 ++-- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java index d96cfe9150b17..314fa845c1417 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java @@ -2733,6 +2733,10 @@ public static boolean isAclEnabled(Configuration conf) { public static final String NM_LINUX_CONTAINER_CGROUPS_MOUNT_PATH = NM_PREFIX + "linux-container-executor.cgroups.mount-path"; + /** Where the linux container executor should mount cgroups v2 if not found */ + public static final String NM_LINUX_CONTAINER_CGROUPS_V2_MOUNT_PATH = + NM_PREFIX + "linux-container-executor.cgroups.v2.mount-path"; + /** * Whether the apps should run in strict resource usage mode(not allowed to * use spare CPU) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml index aac840866ec94..258ad53c30351 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml @@ -2087,6 +2087,20 @@ yarn.nodemanager.linux-container-executor.cgroups.mount-path + + This property sets the mount path for CGroups v2. + This parameter is optional, and needed to be set only in mixed mode, + when CGroups v2 is mounted in a different path than Cgroups v1. + For example, in hybrid mode, CGroups v1 controllers can be mounted in + /sys/fs/cgroup, while v2 can be mounted in /sys/fs/cgroup/unified folder. + + If this value is not set, the value of + yarn.nodemanager.linux-container-executor.cgroups.mount-path + will be used for CGroups v2 as well. + + yarn.nodemanager.linux-container-executor.cgroups.v2.mount-path + + Delay in ms between attempts to remove linux cgroup yarn.nodemanager.linux-container-executor.cgroups.delete-delay-ms 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/CGroupsMountConfig.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/CGroupsMountConfig.java index 6eb8667f2a808..43db8ab97782c 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/CGroupsMountConfig.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/CGroupsMountConfig.java @@ -25,12 +25,18 @@ public class CGroupsMountConfig { private final boolean enableMount; private final String mountPath; + + // CGroups v2 mount path is only relevant in mixed CGroups v1/v2 mode, + // where v2 can be mounted in a different folder than v1. + private final String v2MountPath; public CGroupsMountConfig(Configuration conf) { this.enableMount = conf.getBoolean(YarnConfiguration. NM_LINUX_CONTAINER_CGROUPS_MOUNT, false); this.mountPath = conf.get(YarnConfiguration. NM_LINUX_CONTAINER_CGROUPS_MOUNT_PATH, null); + this.v2MountPath = conf.get(YarnConfiguration. + NM_LINUX_CONTAINER_CGROUPS_V2_MOUNT_PATH, mountPath); } public boolean ensureMountPathIsDefined() throws ResourceHandlerException { @@ -62,11 +68,16 @@ public String getMountPath() { return mountPath; } + public String getV2MountPath() { + return v2MountPath; + } + @Override public String toString() { return "CGroupsMountConfig{" + "enableMount=" + enableMount + - ", mountPath='" + mountPath + '\'' + + ", mountPath='" + mountPath + + ", v2MountPath='" + v2MountPath + '\'' + '}'; } } 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/CGroupsV2HandlerImpl.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/CGroupsV2HandlerImpl.java index cd362ab9a548c..356a4c42dfb31 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/CGroupsV2HandlerImpl.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/CGroupsV2HandlerImpl.java @@ -97,8 +97,8 @@ protected List getCGroupControllers() { @Override protected Map> parsePreConfiguredMountPath() throws IOException { Map> controllerMappings = new HashMap<>(); - controllerMappings.put(this.cGroupsMountConfig.getMountPath(), - readControllersFile(this.cGroupsMountConfig.getMountPath())); + controllerMappings.put(this.cGroupsMountConfig.getV2MountPath(), + readControllersFile(this.cGroupsMountConfig.getV2MountPath())); return controllerMappings; } From a1091077b74976326e669a4d4b861eb142ed59bf Mon Sep 17 00:00:00 2001 From: Peter Szucs Date: Mon, 13 May 2024 20:22:31 +0200 Subject: [PATCH 3/6] YARN-11692. Added unit tests Change-Id: I6b76ff4c8afb2249fa38ff43195e66b446b212c6 --- .../resources/TestCGroupsV2HandlerImpl.java | 148 +++++++++++++++++- 1 file changed, 144 insertions(+), 4 deletions(-) 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/TestCGroupsV2HandlerImpl.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/TestCGroupsV2HandlerImpl.java index 1198cda7ab050..67c5dd5a4d5f7 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/TestCGroupsV2HandlerImpl.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/TestCGroupsV2HandlerImpl.java @@ -210,6 +210,111 @@ public void testMtabParsing() throws Exception { Assert.assertEquals(parentDir.getAbsolutePath(), memoryDir); } + /* + * Create a mock mtab file with the following content for hybrid v1/v2: + * cgroup2 /path/to/parentV2Dir cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot 0 0 + * cgroup /path/to/parentDir cgroup rw,nosuid,nodev,noexec,relatime,memory 0 0 + * + * Create the following cgroup hierarchy: + * + * parentDir + * ___________________________ + * / \ + * unified memory + * _________________________________________________ + * / \ \ + * cgroup.controllers cgroup.subtree_control test-hadoop-yarn (hierarchyDir) + * _________________ + * / \ + * cgroup.controllers cgroup.subtree_control + */ + public File createPremountedHybridCgroups(File v1ParentDir) + throws IOException { + File v2ParentDir = new File(v1ParentDir, "unified"); + + String mtabContent = + "cgroup " + v1ParentDir.getAbsolutePath() + "/memory" + + " cgroup rw,nosuid,nodev,noexec,relatime,memory 0 0\n" + + "cgroup2 " + v2ParentDir.getAbsolutePath() + + " cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot 0 0\n"; + + File mockMtab = createFileWithContent(v1ParentDir, UUID.randomUUID().toString(), mtabContent); + + String enabledV2Controllers = "cpuset cpu io hugetlb pids rdma misc\n"; + File controllersFile = createFileWithContent(v2ParentDir, CGroupsHandler.CGROUP_CONTROLLERS_FILE, + enabledV2Controllers); + + File subtreeControlFile = new File(v2ParentDir, CGroupsHandler.CGROUP_SUBTREE_CONTROL_FILE); + Assert.assertTrue("empty subtree_control file should be created", + subtreeControlFile.createNewFile()); + + File hierarchyDir = new File(v2ParentDir, hierarchy); + if (!hierarchyDir.mkdirs()) { + String message = "Could not create directory " + hierarchyDir.getAbsolutePath(); + throw new IOException(message); + } + hierarchyDir.deleteOnExit(); + + FileUtils.copyFile(controllersFile, new File(hierarchyDir, + CGroupsHandler.CGROUP_CONTROLLERS_FILE)); + FileUtils.copyFile(subtreeControlFile, new File(hierarchyDir, + CGroupsHandler.CGROUP_SUBTREE_CONTROL_FILE)); + + return mockMtab; + } + + @Test + public void testHybridMtabParsing() throws Exception { + // Initialize mtab and cgroup dir + File v1ParentDir = new File(tmpPath); + + File v2ParentDir = new File(v1ParentDir, "unified"); + Assert.assertTrue("temp dir should be created", v2ParentDir.mkdirs()); + v2ParentDir.deleteOnExit(); + + // create mock cgroup + File mockMtabFile = createPremountedHybridCgroups(v1ParentDir); + + // create memory cgroup for v1 + File memoryCgroup = new File(v1ParentDir, "memory"); + assertTrue("Directory should be created", memoryCgroup.mkdirs()); + + // init v1 and v2 handlers + CGroupsHandlerImpl cGroupsHandler = new CGroupsHandlerImpl( + createMountConfiguration(), + privilegedOperationExecutorMock, mockMtabFile.getAbsolutePath()); + CGroupsV2HandlerImpl cGroupsV2Handler = new CGroupsV2HandlerImpl( + createMountConfiguration(), + privilegedOperationExecutorMock, mockMtabFile.getAbsolutePath()); + + // Verify resource handlers that are enabled in v1 + Map> newMtab = + cGroupsHandler.parseMtab(mockMtabFile.getAbsolutePath()); + Map controllerv1Paths = + cGroupsHandler.initializeControllerPathsFromMtab( + newMtab); + + Assert.assertEquals(1, controllerv1Paths.size()); + assertTrue(controllerv1Paths + .containsKey(CGroupsHandler.CGroupController.MEMORY)); + String memoryDir = + controllerv1Paths.get(CGroupsHandler.CGroupController.MEMORY); + Assert.assertEquals(memoryCgroup.getAbsolutePath(), memoryDir); + + // Verify resource handlers that are enabled in v2 + newMtab = + cGroupsV2Handler.parseMtab(mockMtabFile.getAbsolutePath()); + Map controllerPaths = + cGroupsV2Handler.initializeControllerPathsFromMtab( + newMtab); + + Assert.assertEquals(3, controllerPaths.size()); + assertTrue(controllerPaths + .containsKey(CGroupsHandler.CGroupController.CPU)); + String cpuDir = controllerPaths.get(CGroupsHandler.CGroupController.CPU); + Assert.assertEquals(v2ParentDir.getAbsolutePath(), cpuDir); + } + @Test public void testManualCgroupSetting() throws Exception { YarnConfiguration conf = new YarnConfiguration(); @@ -217,8 +322,26 @@ public void testManualCgroupSetting() throws Exception { conf.set(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_HIERARCHY, "/hadoop-yarn"); - File baseCgroup = new File(tmpPath); - File subCgroup = new File(tmpPath, "/hadoop-yarn"); + validateCgroupV2Controllers(conf, tmpPath); + } + + @Test + public void testManualHybridCgroupSetting() throws Exception { + String unifiedPath = tmpPath + "/unified"; + + YarnConfiguration conf = new YarnConfiguration(); + conf.set(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_MOUNT_PATH, tmpPath); + conf.set(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_V2_MOUNT_PATH, unifiedPath); + conf.set(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_HIERARCHY, + "/hadoop-yarn"); + + validateCgroupV1Controllers(conf, tmpPath); + validateCgroupV2Controllers(conf, unifiedPath); + } + + private void validateCgroupV2Controllers(YarnConfiguration conf, String mountPath) throws Exception { + File baseCgroup = new File(mountPath); + File subCgroup = new File(mountPath, "/hadoop-yarn"); Assert.assertTrue("temp dir should be created", subCgroup.mkdirs()); subCgroup.deleteOnExit(); @@ -235,8 +358,8 @@ public void testManualCgroupSetting() throws Exception { cGroupsHandler.initializeCGroupController(CGroupsHandler.CGroupController.CPU); Assert.assertEquals("CPU cgroup path was not set", subCgroup.getAbsolutePath(), - new File(cGroupsHandler.getPathForCGroup( - CGroupsHandler.CGroupController.CPU, "")).getAbsolutePath()); + new File(cGroupsHandler.getPathForCGroup( + CGroupsHandler.CGroupController.CPU, "")).getAbsolutePath()); // Verify that the subtree control file was updated String subtreeControllersEnabledString = FileUtils.readFileToString(subtreeControlFile, @@ -276,4 +399,21 @@ public void testManualCgroupSetting() throws Exception { Assert.assertTrue("Controllers not enabled in subtree control file", cGroupsHandler.getValidCGroups().containsAll(subtreeControllersEnabled)); } + + private void validateCgroupV1Controllers(YarnConfiguration conf, String mountPath) + throws ResourceHandlerException { + File blkio = new File(new File(mountPath, "blkio"), "/hadoop-yarn"); + + Assert.assertTrue("temp dir should be created", blkio.mkdirs()); + + CGroupsHandlerImpl cGroupsv1Handler = new CGroupsHandlerImpl(conf, null); + cGroupsv1Handler.initializeCGroupController( + CGroupsHandler.CGroupController.BLKIO); + + Assert.assertEquals("BLKIO CGRoup path was not set", blkio.getAbsolutePath(), + new File(cGroupsv1Handler.getPathForCGroup( + CGroupsHandler.CGroupController.BLKIO, "")).getAbsolutePath()); + + FileUtils.deleteQuietly(blkio); + } } \ No newline at end of file From d7ffa252fc073c2d77881eecc8bfd0aa166ef967 Mon Sep 17 00:00:00 2001 From: Peter Szucs Date: Tue, 14 May 2024 09:17:03 +0200 Subject: [PATCH 4/6] YARN-11692. Fixed review comments Change-Id: Ib7673c9ba18fd7a4f7edde63972fc1ff66bca7de --- .../hadoop/yarn/conf/YarnConfiguration.java | 2 +- .../src/main/resources/yarn-default.xml | 8 +- .../linux/resources/CGroupsMountConfig.java | 4 +- .../resources/ResourceHandlerModule.java | 79 ++++++++----------- .../resources/TestResourceHandlerModule.java | 36 --------- 5 files changed, 39 insertions(+), 90 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java index 314fa845c1417..2a51065404cac 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java @@ -2733,7 +2733,7 @@ public static boolean isAclEnabled(Configuration conf) { public static final String NM_LINUX_CONTAINER_CGROUPS_MOUNT_PATH = NM_PREFIX + "linux-container-executor.cgroups.mount-path"; - /** Where the linux container executor should mount cgroups v2 if not found */ + /** Where the linux container executor should mount cgroups v2 if not found. */ public static final String NM_LINUX_CONTAINER_CGROUPS_V2_MOUNT_PATH = NM_PREFIX + "linux-container-executor.cgroups.v2.mount-path"; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml index 258ad53c30351..275fc08cb2ca9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml @@ -2090,10 +2090,10 @@ This property sets the mount path for CGroups v2. This parameter is optional, and needed to be set only in mixed mode, - when CGroups v2 is mounted in a different path than Cgroups v1. - For example, in hybrid mode, CGroups v1 controllers can be mounted in - /sys/fs/cgroup, while v2 can be mounted in /sys/fs/cgroup/unified folder. - + when CGroups v2 is mounted alongside with Cgroups v1. + For example, in hybrid mode, CGroups v1 controllers can be mounted under /sys/fs/cgroup/ + (for example /sys/fs/cgroup/cpu,cpuacct), while v2 can be mounted in /sys/fs/cgroup/unified folder. + If this value is not set, the value of yarn.nodemanager.linux-container-executor.cgroups.mount-path will be used for CGroups v2 as well. 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/CGroupsMountConfig.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/CGroupsMountConfig.java index 43db8ab97782c..b5a71f6072846 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/CGroupsMountConfig.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/CGroupsMountConfig.java @@ -25,9 +25,9 @@ public class CGroupsMountConfig { private final boolean enableMount; private final String mountPath; - + // CGroups v2 mount path is only relevant in mixed CGroups v1/v2 mode, - // where v2 can be mounted in a different folder than v1. + // where v2 is mounted alongside with v1. private final String v2MountPath; public CGroupsMountConfig(Configuration conf) { 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/ResourceHandlerModule.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/ResourceHandlerModule.java index 5581db72305c6..98492779b01e5 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/ResourceHandlerModule.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/ResourceHandlerModule.java @@ -63,8 +63,8 @@ public class ResourceHandlerModule { * as resource metrics functionality. We need to ensure that the same * instance is used for both. */ - private static volatile CGroupsHandler cGroupsV1Handler; - private static volatile CGroupsHandler cGroupsV2Handler; + private static volatile CGroupsHandler cGroupV1Handler; + private static volatile CGroupsHandler cGroupV2Handler; private static volatile TrafficControlBandwidthHandlerImpl trafficControlBandwidthHandler; private static volatile NetworkPacketTaggingHandlerImpl @@ -76,41 +76,42 @@ public class ResourceHandlerModule { private static volatile CpuResourceHandler cGroupsCpuResourceHandler; - private static void initializeCGroupsHandlers(Configuration conf) throws ResourceHandlerException { - initializeCGroupsV1Handler(conf); + private static void initializeCGroupHandlers(Configuration conf) + throws ResourceHandlerException { + initializeCGroupV1Handler(conf); if (cgroupsV2Enabled) { - initializeCGroupsV2Handler(conf); + initializeCGroupV2Handler(conf); } } - private static void initializeCGroupsV1Handler(Configuration conf) + private static void initializeCGroupV1Handler(Configuration conf) throws ResourceHandlerException { - if (cGroupsV1Handler == null) { + if (cGroupV1Handler == null) { synchronized (CGroupsHandler.class) { - if (cGroupsV1Handler == null) { - cGroupsV1Handler = new CGroupsHandlerImpl( + if (cGroupV1Handler == null) { + cGroupV1Handler = new CGroupsHandlerImpl( conf, PrivilegedOperationExecutor.getInstance(conf)); - LOG.debug("Value of CGroupsV1Handler is: {}", cGroupsV1Handler); + LOG.debug("Value of CGroupsV1Handler is: {}", cGroupV1Handler); } } } } - private static void initializeCGroupsV2Handler(Configuration conf) + private static void initializeCGroupV2Handler(Configuration conf) throws ResourceHandlerException { - if (cGroupsV2Handler == null) { + if (cGroupV2Handler == null) { synchronized (CGroupsHandler.class) { - if (cGroupsV2Handler == null) { - cGroupsV2Handler = new CGroupsV2HandlerImpl( + if (cGroupV2Handler == null) { + cGroupV2Handler = new CGroupsV2HandlerImpl( conf, PrivilegedOperationExecutor.getInstance(conf)); - LOG.debug("Value of CGroupsV2Handler is: {}", cGroupsV2Handler); + LOG.debug("Value of CGroupsV2Handler is: {}", cGroupV2Handler); } } } } private static boolean isMountedInCGroupsV2(CGroupsHandler.CGroupController controller) { - return (cGroupsV2Handler != null && cGroupsV2Handler.getControllerPath(controller) != null); + return (cGroupV2Handler != null && cGroupV2Handler.getControllerPath(controller) != null); } /** @@ -120,7 +121,7 @@ private static boolean isMountedInCGroupsV2(CGroupsHandler.CGroupController cont */ public static CGroupsHandler getCGroupsHandler() { - return cgroupsV2Enabled ? cGroupsV2Handler : cGroupsV1Handler; + return cGroupV1Handler; } /** @@ -173,11 +174,11 @@ private static CpuResourceHandler initCGroupsCpuResourceHandler( if (cGroupsCpuResourceHandler == null) { LOG.debug("Creating new cgroups cpu handler"); - initializeCGroupsHandlers(conf); + initializeCGroupHandlers(conf); if (isMountedInCGroupsV2(CGroupsHandler.CGroupController.CPU)) { - cGroupsCpuResourceHandler = new CGroupsV2CpuResourceHandlerImpl(cGroupsV2Handler); + cGroupsCpuResourceHandler = new CGroupsV2CpuResourceHandlerImpl(cGroupV2Handler); } else { - cGroupsCpuResourceHandler = new CGroupsCpuResourceHandlerImpl(cGroupsV1Handler); + cGroupsCpuResourceHandler = new CGroupsCpuResourceHandlerImpl(cGroupV1Handler); } return cGroupsCpuResourceHandler; } @@ -197,10 +198,10 @@ private static CpuResourceHandler initCGroupsCpuResourceHandler( if (trafficControlBandwidthHandler == null) { LOG.info("Creating new traffic control bandwidth handler."); - initializeCGroupsHandlers(conf); + initializeCGroupHandlers(conf); trafficControlBandwidthHandler = new TrafficControlBandwidthHandlerImpl(PrivilegedOperationExecutor - .getInstance(conf), cGroupsV1Handler, + .getInstance(conf), cGroupV1Handler, new TrafficController(conf, PrivilegedOperationExecutor .getInstance(conf))); } @@ -234,10 +235,10 @@ public static ResourceHandler getNetworkTaggingHandler(Configuration conf) if (networkPacketTaggingHandlerImpl == null) { LOG.info("Creating new network-tagging-handler."); - initializeCGroupsHandlers(conf); + initializeCGroupHandlers(conf); networkPacketTaggingHandlerImpl = new NetworkPacketTaggingHandlerImpl( - PrivilegedOperationExecutor.getInstance(conf), cGroupsV1Handler); + PrivilegedOperationExecutor.getInstance(conf), cGroupV1Handler); } } } @@ -266,9 +267,9 @@ private static CGroupsBlkioResourceHandlerImpl getCgroupsBlkioResourceHandler( if (cGroupsBlkioResourceHandler == null) { LOG.debug("Creating new cgroups blkio handler"); - initializeCGroupsHandlers(conf); + initializeCGroupHandlers(conf); cGroupsBlkioResourceHandler = - new CGroupsBlkioResourceHandlerImpl(cGroupsV1Handler); + new CGroupsBlkioResourceHandlerImpl(cGroupV1Handler); } } } @@ -291,11 +292,11 @@ public static MemoryResourceHandler initMemoryResourceHandler( synchronized (MemoryResourceHandler.class) { if (cGroupsMemoryResourceHandler == null) { - initializeCGroupsHandlers(conf); + initializeCGroupHandlers(conf); if (isMountedInCGroupsV2(CGroupsHandler.CGroupController.MEMORY)) { - cGroupsMemoryResourceHandler = new CGroupsV2MemoryResourceHandlerImpl(cGroupsV2Handler); + cGroupsMemoryResourceHandler = new CGroupsV2MemoryResourceHandlerImpl(cGroupV2Handler); } else { - cGroupsMemoryResourceHandler = new CGroupsMemoryResourceHandlerImpl(cGroupsV1Handler); + cGroupsMemoryResourceHandler = new CGroupsMemoryResourceHandlerImpl(cGroupV1Handler); } } } @@ -358,10 +359,10 @@ private static void addHandlersFromConfiguredResourcePlugins( } for (ResourcePlugin plugin : pluginMap.values()) { - initializeCGroupsHandlers(conf); + initializeCGroupHandlers(conf); addHandlerIfNotNull(handlerList, plugin.createResourceHandler(nmContext, - cGroupsV1Handler, + cGroupV1Handler, PrivilegedOperationExecutor.getInstance(conf))); } } @@ -392,22 +393,6 @@ static void nullifyResourceHandlerChain() throws ResourceHandlerException { resourceHandlerChain = null; } - @VisibleForTesting - static void resetCGroupsHandlers() { - cGroupsV1Handler = null; - cGroupsV2Handler = null; - } - - @VisibleForTesting - static void resetCpuResourceHandler() { - cGroupsCpuResourceHandler = null; - } - - @VisibleForTesting - static void resetMemoryResourceHandler() { - cGroupsMemoryResourceHandler = null; - } - /** * If a cgroup mount directory is specified, it returns cgroup directories * with valid names. 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/TestResourceHandlerModule.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/TestResourceHandlerModule.java index dc543346d5298..171bfafc4fe7f 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/TestResourceHandlerModule.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/TestResourceHandlerModule.java @@ -49,9 +49,6 @@ public void setup() throws Exception { networkEnabledConf.setBoolean(YarnConfiguration.NM_NETWORK_RESOURCE_ENABLED, true); ResourceHandlerModule.nullifyResourceHandlerChain(); - ResourceHandlerModule.resetCGroupsHandlers(); - ResourceHandlerModule.resetCpuResourceHandler(); - ResourceHandlerModule.resetMemoryResourceHandler(); } @Test @@ -114,37 +111,4 @@ public void testDiskResourceHandler() throws Exception { Assert.fail("Null returned"); } } - - @Test - public void testCgroupsHandlerClassForCgroupV1() throws ResourceHandlerException { - Configuration conf = new YarnConfiguration(); - conf.setBoolean(YarnConfiguration.NM_MEMORY_RESOURCE_ENABLED, true); - conf.setBoolean(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_V2_ENABLED, false); - - initResourceHandlerChain(conf); - - Assert.assertTrue(ResourceHandlerModule.getCGroupsHandler() - instanceof CGroupsHandlerImpl); - } - - @Test - public void testCgroupsHandlerClassForCgroupV2() throws ResourceHandlerException { - Configuration conf = new YarnConfiguration(); - conf.setBoolean(YarnConfiguration.NM_MEMORY_RESOURCE_ENABLED, true); - conf.setBoolean(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_V2_ENABLED, true); - - initResourceHandlerChain(conf); - - Assert.assertTrue(ResourceHandlerModule.getCGroupsHandler() - instanceof CGroupsV2HandlerImpl); - } - - private void initResourceHandlerChain(Configuration conf) throws ResourceHandlerException { - ResourceHandlerChain resourceHandlerChain = - ResourceHandlerModule.getConfiguredResourceHandlerChain(conf, - mock(Context.class)); - if (resourceHandlerChain == null) { - Assert.fail("Could not initialize resource handler chain"); - } - } } \ No newline at end of file From 185d0d3a97a6d01214a3aaeb474b1d38ff8ed644 Mon Sep 17 00:00:00 2001 From: Peter Szucs Date: Tue, 14 May 2024 10:06:16 +0200 Subject: [PATCH 5/6] YARN-11692. Fixed test case description Change-Id: I944acfc508bd89391282e262e0b3b9dd398aa2f9 --- .../linux/resources/TestCGroupsV2HandlerImpl.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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/TestCGroupsV2HandlerImpl.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/TestCGroupsV2HandlerImpl.java index 67c5dd5a4d5f7..8dd0453fe0b97 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/TestCGroupsV2HandlerImpl.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/TestCGroupsV2HandlerImpl.java @@ -213,14 +213,14 @@ public void testMtabParsing() throws Exception { /* * Create a mock mtab file with the following content for hybrid v1/v2: * cgroup2 /path/to/parentV2Dir cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot 0 0 - * cgroup /path/to/parentDir cgroup rw,nosuid,nodev,noexec,relatime,memory 0 0 + * cgroup /path/to/parentDir/memory cgroup rw,nosuid,nodev,noexec,relatime,memory 0 0 * * Create the following cgroup hierarchy: * - * parentDir - * ___________________________ - * / \ - * unified memory + * parentDir + * __________________________________ + * / \ + * unified memory * _________________________________________________ * / \ \ * cgroup.controllers cgroup.subtree_control test-hadoop-yarn (hierarchyDir) From e49e11d112734a35249a343a3c8cbb906f20eec4 Mon Sep 17 00:00:00 2001 From: Peter Szucs Date: Tue, 14 May 2024 13:29:05 +0200 Subject: [PATCH 6/6] YARN-11692. Fixed blanks and checkstyle issues Change-Id: I6de7b4d683444747662fbf6bfd65581f014b08ce --- .../resources/TestCGroupsV2HandlerImpl.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) 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/TestCGroupsV2HandlerImpl.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/TestCGroupsV2HandlerImpl.java index 8dd0453fe0b97..1ec952be049ff 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/TestCGroupsV2HandlerImpl.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/TestCGroupsV2HandlerImpl.java @@ -212,11 +212,11 @@ public void testMtabParsing() throws Exception { /* * Create a mock mtab file with the following content for hybrid v1/v2: - * cgroup2 /path/to/parentV2Dir cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot 0 0 + * cgroup2 /path/to/parentV2Dir cgroup2 rw,nosuid,nodev,noexec,relatime,memory_recursiveprot 0 0 * cgroup /path/to/parentDir/memory cgroup rw,nosuid,nodev,noexec,relatime,memory 0 0 * * Create the following cgroup hierarchy: - * + * * parentDir * __________________________________ * / \ @@ -236,13 +236,13 @@ public File createPremountedHybridCgroups(File v1ParentDir) "cgroup " + v1ParentDir.getAbsolutePath() + "/memory" + " cgroup rw,nosuid,nodev,noexec,relatime,memory 0 0\n" + "cgroup2 " + v2ParentDir.getAbsolutePath() - + " cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot 0 0\n"; - + + " cgroup2 rw,nosuid,nodev,noexec,relatime,memory_recursiveprot 0 0\n"; + File mockMtab = createFileWithContent(v1ParentDir, UUID.randomUUID().toString(), mtabContent); String enabledV2Controllers = "cpuset cpu io hugetlb pids rdma misc\n"; - File controllersFile = createFileWithContent(v2ParentDir, CGroupsHandler.CGROUP_CONTROLLERS_FILE, - enabledV2Controllers); + File controllersFile = createFileWithContent(v2ParentDir, + CGroupsHandler.CGROUP_CONTROLLERS_FILE, enabledV2Controllers); File subtreeControlFile = new File(v2ParentDir, CGroupsHandler.CGROUP_SUBTREE_CONTROL_FILE); Assert.assertTrue("empty subtree_control file should be created", @@ -267,14 +267,14 @@ public File createPremountedHybridCgroups(File v1ParentDir) public void testHybridMtabParsing() throws Exception { // Initialize mtab and cgroup dir File v1ParentDir = new File(tmpPath); - + File v2ParentDir = new File(v1ParentDir, "unified"); Assert.assertTrue("temp dir should be created", v2ParentDir.mkdirs()); v2ParentDir.deleteOnExit(); - + // create mock cgroup File mockMtabFile = createPremountedHybridCgroups(v1ParentDir); - + // create memory cgroup for v1 File memoryCgroup = new File(v1ParentDir, "memory"); assertTrue("Directory should be created", memoryCgroup.mkdirs()); @@ -328,7 +328,7 @@ public void testManualCgroupSetting() throws Exception { @Test public void testManualHybridCgroupSetting() throws Exception { String unifiedPath = tmpPath + "/unified"; - + YarnConfiguration conf = new YarnConfiguration(); conf.set(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_MOUNT_PATH, tmpPath); conf.set(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_V2_MOUNT_PATH, unifiedPath); @@ -339,7 +339,8 @@ public void testManualHybridCgroupSetting() throws Exception { validateCgroupV2Controllers(conf, unifiedPath); } - private void validateCgroupV2Controllers(YarnConfiguration conf, String mountPath) throws Exception { + private void validateCgroupV2Controllers(YarnConfiguration conf, String mountPath) + throws Exception { File baseCgroup = new File(mountPath); File subCgroup = new File(mountPath, "/hadoop-yarn"); Assert.assertTrue("temp dir should be created", subCgroup.mkdirs());