Skip to content

Commit d7ffa25

Browse files
committed
YARN-11692. Fixed review comments
Change-Id: Ib7673c9ba18fd7a4f7edde63972fc1ff66bca7de
1 parent a109107 commit d7ffa25

File tree

5 files changed

+39
-90
lines changed

5 files changed

+39
-90
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2733,7 +2733,7 @@ public static boolean isAclEnabled(Configuration conf) {
27332733
public static final String NM_LINUX_CONTAINER_CGROUPS_MOUNT_PATH =
27342734
NM_PREFIX + "linux-container-executor.cgroups.mount-path";
27352735

2736-
/** Where the linux container executor should mount cgroups v2 if not found */
2736+
/** Where the linux container executor should mount cgroups v2 if not found. */
27372737
public static final String NM_LINUX_CONTAINER_CGROUPS_V2_MOUNT_PATH =
27382738
NM_PREFIX + "linux-container-executor.cgroups.v2.mount-path";
27392739

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,10 +2090,10 @@
20902090
<property>
20912091
<description>This property sets the mount path for CGroups v2.
20922092
This parameter is optional, and needed to be set only in mixed mode,
2093-
when CGroups v2 is mounted in a different path than Cgroups v1.
2094-
For example, in hybrid mode, CGroups v1 controllers can be mounted in
2095-
/sys/fs/cgroup, while v2 can be mounted in /sys/fs/cgroup/unified folder.
2096-
2093+
when CGroups v2 is mounted alongside with Cgroups v1.
2094+
For example, in hybrid mode, CGroups v1 controllers can be mounted under /sys/fs/cgroup/
2095+
(for example /sys/fs/cgroup/cpu,cpuacct), while v2 can be mounted in /sys/fs/cgroup/unified folder.
2096+
20972097
If this value is not set, the value of
20982098
yarn.nodemanager.linux-container-executor.cgroups.mount-path
20992099
will be used for CGroups v2 as well.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
public class CGroupsMountConfig {
2626
private final boolean enableMount;
2727
private final String mountPath;
28-
28+
2929
// CGroups v2 mount path is only relevant in mixed CGroups v1/v2 mode,
30-
// where v2 can be mounted in a different folder than v1.
30+
// where v2 is mounted alongside with v1.
3131
private final String v2MountPath;
3232

3333
public CGroupsMountConfig(Configuration conf) {

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

Lines changed: 32 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public class ResourceHandlerModule {
6363
* as resource metrics functionality. We need to ensure that the same
6464
* instance is used for both.
6565
*/
66-
private static volatile CGroupsHandler cGroupsV1Handler;
67-
private static volatile CGroupsHandler cGroupsV2Handler;
66+
private static volatile CGroupsHandler cGroupV1Handler;
67+
private static volatile CGroupsHandler cGroupV2Handler;
6868
private static volatile TrafficControlBandwidthHandlerImpl
6969
trafficControlBandwidthHandler;
7070
private static volatile NetworkPacketTaggingHandlerImpl
@@ -76,41 +76,42 @@ public class ResourceHandlerModule {
7676
private static volatile CpuResourceHandler
7777
cGroupsCpuResourceHandler;
7878

79-
private static void initializeCGroupsHandlers(Configuration conf) throws ResourceHandlerException {
80-
initializeCGroupsV1Handler(conf);
79+
private static void initializeCGroupHandlers(Configuration conf)
80+
throws ResourceHandlerException {
81+
initializeCGroupV1Handler(conf);
8182
if (cgroupsV2Enabled) {
82-
initializeCGroupsV2Handler(conf);
83+
initializeCGroupV2Handler(conf);
8384
}
8485
}
8586

86-
private static void initializeCGroupsV1Handler(Configuration conf)
87+
private static void initializeCGroupV1Handler(Configuration conf)
8788
throws ResourceHandlerException {
88-
if (cGroupsV1Handler == null) {
89+
if (cGroupV1Handler == null) {
8990
synchronized (CGroupsHandler.class) {
90-
if (cGroupsV1Handler == null) {
91-
cGroupsV1Handler = new CGroupsHandlerImpl(
91+
if (cGroupV1Handler == null) {
92+
cGroupV1Handler = new CGroupsHandlerImpl(
9293
conf, PrivilegedOperationExecutor.getInstance(conf));
93-
LOG.debug("Value of CGroupsV1Handler is: {}", cGroupsV1Handler);
94+
LOG.debug("Value of CGroupsV1Handler is: {}", cGroupV1Handler);
9495
}
9596
}
9697
}
9798
}
9899

99-
private static void initializeCGroupsV2Handler(Configuration conf)
100+
private static void initializeCGroupV2Handler(Configuration conf)
100101
throws ResourceHandlerException {
101-
if (cGroupsV2Handler == null) {
102+
if (cGroupV2Handler == null) {
102103
synchronized (CGroupsHandler.class) {
103-
if (cGroupsV2Handler == null) {
104-
cGroupsV2Handler = new CGroupsV2HandlerImpl(
104+
if (cGroupV2Handler == null) {
105+
cGroupV2Handler = new CGroupsV2HandlerImpl(
105106
conf, PrivilegedOperationExecutor.getInstance(conf));
106-
LOG.debug("Value of CGroupsV2Handler is: {}", cGroupsV2Handler);
107+
LOG.debug("Value of CGroupsV2Handler is: {}", cGroupV2Handler);
107108
}
108109
}
109110
}
110111
}
111112

112113
private static boolean isMountedInCGroupsV2(CGroupsHandler.CGroupController controller) {
113-
return (cGroupsV2Handler != null && cGroupsV2Handler.getControllerPath(controller) != null);
114+
return (cGroupV2Handler != null && cGroupV2Handler.getControllerPath(controller) != null);
114115
}
115116

116117
/**
@@ -120,7 +121,7 @@ private static boolean isMountedInCGroupsV2(CGroupsHandler.CGroupController cont
120121
*/
121122

122123
public static CGroupsHandler getCGroupsHandler() {
123-
return cgroupsV2Enabled ? cGroupsV2Handler : cGroupsV1Handler;
124+
return cGroupV1Handler;
124125
}
125126

126127
/**
@@ -173,11 +174,11 @@ private static CpuResourceHandler initCGroupsCpuResourceHandler(
173174
if (cGroupsCpuResourceHandler == null) {
174175
LOG.debug("Creating new cgroups cpu handler");
175176

176-
initializeCGroupsHandlers(conf);
177+
initializeCGroupHandlers(conf);
177178
if (isMountedInCGroupsV2(CGroupsHandler.CGroupController.CPU)) {
178-
cGroupsCpuResourceHandler = new CGroupsV2CpuResourceHandlerImpl(cGroupsV2Handler);
179+
cGroupsCpuResourceHandler = new CGroupsV2CpuResourceHandlerImpl(cGroupV2Handler);
179180
} else {
180-
cGroupsCpuResourceHandler = new CGroupsCpuResourceHandlerImpl(cGroupsV1Handler);
181+
cGroupsCpuResourceHandler = new CGroupsCpuResourceHandlerImpl(cGroupV1Handler);
181182
}
182183
return cGroupsCpuResourceHandler;
183184
}
@@ -197,10 +198,10 @@ private static CpuResourceHandler initCGroupsCpuResourceHandler(
197198
if (trafficControlBandwidthHandler == null) {
198199
LOG.info("Creating new traffic control bandwidth handler.");
199200

200-
initializeCGroupsHandlers(conf);
201+
initializeCGroupHandlers(conf);
201202
trafficControlBandwidthHandler = new
202203
TrafficControlBandwidthHandlerImpl(PrivilegedOperationExecutor
203-
.getInstance(conf), cGroupsV1Handler,
204+
.getInstance(conf), cGroupV1Handler,
204205
new TrafficController(conf, PrivilegedOperationExecutor
205206
.getInstance(conf)));
206207
}
@@ -234,10 +235,10 @@ public static ResourceHandler getNetworkTaggingHandler(Configuration conf)
234235
if (networkPacketTaggingHandlerImpl == null) {
235236
LOG.info("Creating new network-tagging-handler.");
236237

237-
initializeCGroupsHandlers(conf);
238+
initializeCGroupHandlers(conf);
238239
networkPacketTaggingHandlerImpl =
239240
new NetworkPacketTaggingHandlerImpl(
240-
PrivilegedOperationExecutor.getInstance(conf), cGroupsV1Handler);
241+
PrivilegedOperationExecutor.getInstance(conf), cGroupV1Handler);
241242
}
242243
}
243244
}
@@ -266,9 +267,9 @@ private static CGroupsBlkioResourceHandlerImpl getCgroupsBlkioResourceHandler(
266267
if (cGroupsBlkioResourceHandler == null) {
267268
LOG.debug("Creating new cgroups blkio handler");
268269

269-
initializeCGroupsHandlers(conf);
270+
initializeCGroupHandlers(conf);
270271
cGroupsBlkioResourceHandler =
271-
new CGroupsBlkioResourceHandlerImpl(cGroupsV1Handler);
272+
new CGroupsBlkioResourceHandlerImpl(cGroupV1Handler);
272273
}
273274
}
274275
}
@@ -291,11 +292,11 @@ public static MemoryResourceHandler initMemoryResourceHandler(
291292
synchronized (MemoryResourceHandler.class) {
292293
if (cGroupsMemoryResourceHandler == null) {
293294

294-
initializeCGroupsHandlers(conf);
295+
initializeCGroupHandlers(conf);
295296
if (isMountedInCGroupsV2(CGroupsHandler.CGroupController.MEMORY)) {
296-
cGroupsMemoryResourceHandler = new CGroupsV2MemoryResourceHandlerImpl(cGroupsV2Handler);
297+
cGroupsMemoryResourceHandler = new CGroupsV2MemoryResourceHandlerImpl(cGroupV2Handler);
297298
} else {
298-
cGroupsMemoryResourceHandler = new CGroupsMemoryResourceHandlerImpl(cGroupsV1Handler);
299+
cGroupsMemoryResourceHandler = new CGroupsMemoryResourceHandlerImpl(cGroupV1Handler);
299300
}
300301
}
301302
}
@@ -358,10 +359,10 @@ private static void addHandlersFromConfiguredResourcePlugins(
358359
}
359360

360361
for (ResourcePlugin plugin : pluginMap.values()) {
361-
initializeCGroupsHandlers(conf);
362+
initializeCGroupHandlers(conf);
362363
addHandlerIfNotNull(handlerList,
363364
plugin.createResourceHandler(nmContext,
364-
cGroupsV1Handler,
365+
cGroupV1Handler,
365366
PrivilegedOperationExecutor.getInstance(conf)));
366367
}
367368
}
@@ -392,22 +393,6 @@ static void nullifyResourceHandlerChain() throws ResourceHandlerException {
392393
resourceHandlerChain = null;
393394
}
394395

395-
@VisibleForTesting
396-
static void resetCGroupsHandlers() {
397-
cGroupsV1Handler = null;
398-
cGroupsV2Handler = null;
399-
}
400-
401-
@VisibleForTesting
402-
static void resetCpuResourceHandler() {
403-
cGroupsCpuResourceHandler = null;
404-
}
405-
406-
@VisibleForTesting
407-
static void resetMemoryResourceHandler() {
408-
cGroupsMemoryResourceHandler = null;
409-
}
410-
411396
/**
412397
* If a cgroup mount directory is specified, it returns cgroup directories
413398
* with valid names.

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

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ public void setup() throws Exception {
4949
networkEnabledConf.setBoolean(YarnConfiguration.NM_NETWORK_RESOURCE_ENABLED,
5050
true);
5151
ResourceHandlerModule.nullifyResourceHandlerChain();
52-
ResourceHandlerModule.resetCGroupsHandlers();
53-
ResourceHandlerModule.resetCpuResourceHandler();
54-
ResourceHandlerModule.resetMemoryResourceHandler();
5552
}
5653

5754
@Test
@@ -114,37 +111,4 @@ public void testDiskResourceHandler() throws Exception {
114111
Assert.fail("Null returned");
115112
}
116113
}
117-
118-
@Test
119-
public void testCgroupsHandlerClassForCgroupV1() throws ResourceHandlerException {
120-
Configuration conf = new YarnConfiguration();
121-
conf.setBoolean(YarnConfiguration.NM_MEMORY_RESOURCE_ENABLED, true);
122-
conf.setBoolean(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_V2_ENABLED, false);
123-
124-
initResourceHandlerChain(conf);
125-
126-
Assert.assertTrue(ResourceHandlerModule.getCGroupsHandler()
127-
instanceof CGroupsHandlerImpl);
128-
}
129-
130-
@Test
131-
public void testCgroupsHandlerClassForCgroupV2() throws ResourceHandlerException {
132-
Configuration conf = new YarnConfiguration();
133-
conf.setBoolean(YarnConfiguration.NM_MEMORY_RESOURCE_ENABLED, true);
134-
conf.setBoolean(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_V2_ENABLED, true);
135-
136-
initResourceHandlerChain(conf);
137-
138-
Assert.assertTrue(ResourceHandlerModule.getCGroupsHandler()
139-
instanceof CGroupsV2HandlerImpl);
140-
}
141-
142-
private void initResourceHandlerChain(Configuration conf) throws ResourceHandlerException {
143-
ResourceHandlerChain resourceHandlerChain =
144-
ResourceHandlerModule.getConfiguredResourceHandlerChain(conf,
145-
mock(Context.class));
146-
if (resourceHandlerChain == null) {
147-
Assert.fail("Could not initialize resource handler chain");
148-
}
149-
}
150114
}

0 commit comments

Comments
 (0)