Skip to content

Commit 189c8b6

Browse files
authored
YARN-11813. Fix the fallback ordering between cgroup v2 and v1. (#7631)
1 parent ed7e7da commit 189c8b6

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
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/CGroupsV2HandlerImpl.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,22 @@ protected List<CGroupController> getCGroupControllers() {
9595
}
9696

9797
@Override
98-
protected Map<String, Set<String>> parsePreConfiguredMountPath() throws IOException {
98+
protected Map<String, Set<String>> parsePreConfiguredMountPath() {
9999
Map<String, Set<String>> controllerMappings = new HashMap<>();
100-
controllerMappings.put(this.cGroupsMountConfig.getV2MountPath(),
101-
readControllersFile(this.cGroupsMountConfig.getV2MountPath()));
100+
try {
101+
controllerMappings.put(this.cGroupsMountConfig.getV2MountPath(),
102+
readControllersFile(this.cGroupsMountConfig.getV2MountPath()));
103+
} catch (IOException e) {
104+
// Failing to read the cgroup.controllers file in the preconfigured might mean
105+
// that the node is not using cgroup v2, or no cgroup v2 hierarchy is mounted
106+
// under the specified path. If the node is using v1 we will fall back to cgroup v1
107+
// in ResourceHandlerModule.initializeCGroupHandlers. If the cgroup v2 hierarchy is
108+
// not mounted and no cgroup v1 hierarchy is mounted, we will fail to start the NM.
109+
LOG.info("Failed to read the cgroup controllers file in the preconfigured directory: {}. " +
110+
"The cgroup v2 hierarchy may not be mounted under the specified path, or the node" +
111+
" might be using cgroup v1.", this.cGroupsMountConfig.getV2MountPath());
112+
LOG.debug("Exception while reading the cgroup.controllers file: ", e);
113+
}
102114
return controllerMappings;
103115
}
104116

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: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,17 @@ public class ResourceHandlerModule {
7777
cGroupsCpuResourceHandler;
7878

7979
private static void initializeCGroupHandlers(Configuration conf,
80-
CGroupsHandler.CGroupController controller) throws ResourceHandlerException {
81-
initializeCGroupV1Handler(conf);
82-
if (cgroupsV2Enabled && !isMountedInCGroupsV1(controller)) {
80+
CGroupsHandler.CGroupController controller)
81+
throws ResourceHandlerException {
82+
if (cgroupsV2Enabled) {
8383
initializeCGroupV2Handler(conf);
84+
if (!isMountedInCGroupsV2(controller)) {
85+
LOG.info("Cgroup v2 is enabled but {} is not mounted in cgroups v2, falling back to v1",
86+
controller);
87+
initializeCGroupV1Handler(conf);
88+
}
89+
} else {
90+
initializeCGroupV1Handler(conf);
8491
}
8592
}
8693

0 commit comments

Comments
 (0)