Skip to content

Commit 6e6abaa

Browse files
committed
YARN-11743. Cgroup v2 support should fall back to v1 when there are no v2 controllers
Change-Id: Ia6e80c5e4273af71c42e6e5efe64c7c91769a36e
1 parent aa5fe6f commit 6e6abaa

File tree

1 file changed

+13
-9
lines changed
  • hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources

1 file changed

+13
-9
lines changed

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: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ public class ResourceHandlerModule {
7676
private static volatile CpuResourceHandler
7777
cGroupsCpuResourceHandler;
7878

79-
private static void initializeCGroupHandlers(Configuration conf)
80-
throws ResourceHandlerException {
79+
private static void initializeCGroupHandlers(Configuration conf,
80+
CGroupsHandler.CGroupController controller) throws ResourceHandlerException {
8181
initializeCGroupV1Handler(conf);
82-
if (cgroupsV2Enabled) {
82+
if (cgroupsV2Enabled && !isMountedInCGroupsV1(controller)) {
8383
initializeCGroupV2Handler(conf);
8484
}
8585
}
@@ -110,6 +110,10 @@ private static void initializeCGroupV2Handler(Configuration conf)
110110
}
111111
}
112112

113+
private static boolean isMountedInCGroupsV1(CGroupsHandler.CGroupController controller) {
114+
return (cGroupV1Handler != null && cGroupV1Handler.getControllerPath(controller) != null);
115+
}
116+
113117
private static boolean isMountedInCGroupsV2(CGroupsHandler.CGroupController controller) {
114118
return (cGroupV2Handler != null && cGroupV2Handler.getControllerPath(controller) != null);
115119
}
@@ -174,7 +178,7 @@ private static CpuResourceHandler initCGroupsCpuResourceHandler(
174178
if (cGroupsCpuResourceHandler == null) {
175179
LOG.debug("Creating new cgroups cpu handler");
176180

177-
initializeCGroupHandlers(conf);
181+
initializeCGroupHandlers(conf, CGroupsHandler.CGroupController.CPU);
178182
if (isMountedInCGroupsV2(CGroupsHandler.CGroupController.CPU)) {
179183
cGroupsCpuResourceHandler = new CGroupsV2CpuResourceHandlerImpl(cGroupV2Handler);
180184
} else {
@@ -198,7 +202,7 @@ private static CpuResourceHandler initCGroupsCpuResourceHandler(
198202
if (trafficControlBandwidthHandler == null) {
199203
LOG.info("Creating new traffic control bandwidth handler.");
200204

201-
initializeCGroupHandlers(conf);
205+
initializeCGroupHandlers(conf, CGroupsHandler.CGroupController.NET_CLS);
202206
trafficControlBandwidthHandler = new
203207
TrafficControlBandwidthHandlerImpl(PrivilegedOperationExecutor
204208
.getInstance(conf), cGroupV1Handler,
@@ -235,7 +239,7 @@ public static ResourceHandler getNetworkTaggingHandler(Configuration conf)
235239
if (networkPacketTaggingHandlerImpl == null) {
236240
LOG.info("Creating new network-tagging-handler.");
237241

238-
initializeCGroupHandlers(conf);
242+
initializeCGroupHandlers(conf, CGroupsHandler.CGroupController.NET_CLS);
239243
networkPacketTaggingHandlerImpl =
240244
new NetworkPacketTaggingHandlerImpl(
241245
PrivilegedOperationExecutor.getInstance(conf), cGroupV1Handler);
@@ -267,7 +271,7 @@ private static CGroupsBlkioResourceHandlerImpl getCgroupsBlkioResourceHandler(
267271
if (cGroupsBlkioResourceHandler == null) {
268272
LOG.debug("Creating new cgroups blkio handler");
269273

270-
initializeCGroupHandlers(conf);
274+
initializeCGroupHandlers(conf, CGroupsHandler.CGroupController.BLKIO);
271275
cGroupsBlkioResourceHandler =
272276
new CGroupsBlkioResourceHandlerImpl(cGroupV1Handler);
273277
}
@@ -292,7 +296,7 @@ public static MemoryResourceHandler initMemoryResourceHandler(
292296
synchronized (MemoryResourceHandler.class) {
293297
if (cGroupsMemoryResourceHandler == null) {
294298

295-
initializeCGroupHandlers(conf);
299+
initializeCGroupHandlers(conf, CGroupsHandler.CGroupController.MEMORY);
296300
if (isMountedInCGroupsV2(CGroupsHandler.CGroupController.MEMORY)) {
297301
cGroupsMemoryResourceHandler = new CGroupsV2MemoryResourceHandlerImpl(cGroupV2Handler);
298302
} else {
@@ -359,7 +363,7 @@ private static void addHandlersFromConfiguredResourcePlugins(
359363
}
360364

361365
for (ResourcePlugin plugin : pluginMap.values()) {
362-
initializeCGroupHandlers(conf);
366+
initializeCGroupV1Handler(conf);
363367
addHandlerIfNotNull(handlerList,
364368
plugin.createResourceHandler(nmContext,
365369
cGroupV1Handler,

0 commit comments

Comments
 (0)