|
@@ -27,6 +27,7 @@ import java.io.InputStreamReader;
|
|
|
import java.io.OutputStreamWriter;
|
|
|
import java.io.PrintWriter;
|
|
|
import java.io.Writer;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
@@ -39,7 +40,6 @@ import java.util.regex.Pattern;
|
|
|
|
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
|
|
|
|
-import com.google.common.collect.Sets;
|
|
|
import org.apache.commons.logging.Log;
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
@@ -51,6 +51,8 @@ import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
|
import org.apache.hadoop.yarn.server.nodemanager.LinuxContainerExecutor;
|
|
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperation;
|
|
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources.CGroupsCpuResourceHandlerImpl;
|
|
|
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources.CGroupsHandler;
|
|
|
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources.ResourceHandlerModule;
|
|
|
import org.apache.hadoop.yarn.util.Clock;
|
|
|
import org.apache.hadoop.yarn.util.ResourceCalculatorPlugin;
|
|
|
import org.apache.hadoop.yarn.util.SystemClock;
|
|
@@ -87,11 +89,11 @@ public class CgroupsLCEResourcesHandler implements LCEResourcesHandler {
|
|
|
|
|
|
private long deleteCgroupTimeout;
|
|
|
private long deleteCgroupDelay;
|
|
|
- // package private for testing purposes
|
|
|
+ @VisibleForTesting
|
|
|
Clock clock;
|
|
|
|
|
|
private float yarnProcessors;
|
|
|
- int nodeVCores;
|
|
|
+ private int nodeVCores;
|
|
|
|
|
|
public CgroupsLCEResourcesHandler() {
|
|
|
this.controllerPaths = new HashMap<String, String>();
|
|
@@ -132,8 +134,10 @@ public class CgroupsLCEResourcesHandler implements LCEResourcesHandler {
|
|
|
this.strictResourceUsageMode =
|
|
|
conf
|
|
|
.getBoolean(
|
|
|
- YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_STRICT_RESOURCE_USAGE,
|
|
|
- YarnConfiguration.DEFAULT_NM_LINUX_CONTAINER_CGROUPS_STRICT_RESOURCE_USAGE);
|
|
|
+ YarnConfiguration
|
|
|
+ .NM_LINUX_CONTAINER_CGROUPS_STRICT_RESOURCE_USAGE,
|
|
|
+ YarnConfiguration
|
|
|
+ .DEFAULT_NM_LINUX_CONTAINER_CGROUPS_STRICT_RESOURCE_USAGE);
|
|
|
|
|
|
int len = cgroupPrefix.length();
|
|
|
if (cgroupPrefix.charAt(len - 1) == '/') {
|
|
@@ -169,8 +173,10 @@ public class CgroupsLCEResourcesHandler implements LCEResourcesHandler {
|
|
|
if (systemProcessors != (int) yarnProcessors) {
|
|
|
LOG.info("YARN containers restricted to " + yarnProcessors + " cores");
|
|
|
int[] limits = getOverallLimits(yarnProcessors);
|
|
|
- updateCgroup(CONTROLLER_CPU, "", CPU_PERIOD_US, String.valueOf(limits[0]));
|
|
|
- updateCgroup(CONTROLLER_CPU, "", CPU_QUOTA_US, String.valueOf(limits[1]));
|
|
|
+ updateCgroup(CONTROLLER_CPU, "", CPU_PERIOD_US,
|
|
|
+ String.valueOf(limits[0]));
|
|
|
+ updateCgroup(CONTROLLER_CPU, "", CPU_QUOTA_US,
|
|
|
+ String.valueOf(limits[1]));
|
|
|
} else if (CGroupsCpuResourceHandlerImpl.cpuLimitsExist(
|
|
|
pathForCgroup(CONTROLLER_CPU, ""))) {
|
|
|
LOG.info("Removing CPU constraints for YARN containers.");
|
|
@@ -178,8 +184,8 @@ public class CgroupsLCEResourcesHandler implements LCEResourcesHandler {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- int[] getOverallLimits(float yarnProcessors) {
|
|
|
- return CGroupsCpuResourceHandlerImpl.getOverallLimits(yarnProcessors);
|
|
|
+ int[] getOverallLimits(float yarnProcessorsArg) {
|
|
|
+ return CGroupsCpuResourceHandlerImpl.getOverallLimits(yarnProcessorsArg);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -204,7 +210,7 @@ public class CgroupsLCEResourcesHandler implements LCEResourcesHandler {
|
|
|
LOG.debug("createCgroup: " + path);
|
|
|
}
|
|
|
|
|
|
- if (! new File(path).mkdir()) {
|
|
|
+ if (!new File(path).mkdir()) {
|
|
|
throw new IOException("Failed to create cgroup at " + path);
|
|
|
}
|
|
|
}
|
|
@@ -251,7 +257,8 @@ public class CgroupsLCEResourcesHandler implements LCEResourcesHandler {
|
|
|
try (BufferedReader inl =
|
|
|
new BufferedReader(new InputStreamReader(new FileInputStream(cgf
|
|
|
+ "/tasks"), "UTF-8"))) {
|
|
|
- if ((str = inl.readLine()) != null) {
|
|
|
+ str = inl.readLine();
|
|
|
+ if (str != null) {
|
|
|
LOG.debug("First line in cgroup tasks file: " + cgf + " " + str);
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
@@ -337,9 +344,9 @@ public class CgroupsLCEResourcesHandler implements LCEResourcesHandler {
|
|
|
(containerVCores * yarnProcessors) / (float) nodeVCores;
|
|
|
int[] limits = getOverallLimits(containerCPU);
|
|
|
updateCgroup(CONTROLLER_CPU, containerName, CPU_PERIOD_US,
|
|
|
- String.valueOf(limits[0]));
|
|
|
+ String.valueOf(limits[0]));
|
|
|
updateCgroup(CONTROLLER_CPU, containerName, CPU_QUOTA_US,
|
|
|
- String.valueOf(limits[1]));
|
|
|
+ String.valueOf(limits[1]));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -400,6 +407,8 @@ public class CgroupsLCEResourcesHandler implements LCEResourcesHandler {
|
|
|
private Map<String, Set<String>> parseMtab() throws IOException {
|
|
|
Map<String, Set<String>> ret = new HashMap<String, Set<String>>();
|
|
|
BufferedReader in = null;
|
|
|
+ Set<String> validCgroups =
|
|
|
+ CGroupsHandler.CGroupController.getValidCGroups();
|
|
|
|
|
|
try {
|
|
|
FileInputStream fis = new FileInputStream(new File(getMtabFileName()));
|
|
@@ -415,8 +424,11 @@ public class CgroupsLCEResourcesHandler implements LCEResourcesHandler {
|
|
|
String options = m.group(3);
|
|
|
|
|
|
if (type.equals(CGROUPS_FSTYPE)) {
|
|
|
- HashSet<String> value = Sets.newHashSet(options.split(","));
|
|
|
- ret.put(path, value);
|
|
|
+ Set<String> cgroupList =
|
|
|
+ new HashSet<>(Arrays.asList(options.split(",")));
|
|
|
+ // Collect the valid subsystem names
|
|
|
+ cgroupList.retainAll(validCgroups);
|
|
|
+ ret.put(path, cgroupList);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -448,7 +460,16 @@ public class CgroupsLCEResourcesHandler implements LCEResourcesHandler {
|
|
|
|
|
|
private void initializeControllerPaths() throws IOException {
|
|
|
String controllerPath;
|
|
|
- Map<String, Set<String>> parsedMtab = parseMtab();
|
|
|
+ Map<String, Set<String>> parsedMtab = null;
|
|
|
+
|
|
|
+ if (this.cgroupMountPath != null && !this.cgroupMount) {
|
|
|
+ parsedMtab = ResourceHandlerModule.
|
|
|
+ parseConfiguredCGroupPath(this.cgroupMountPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (parsedMtab == null) {
|
|
|
+ parsedMtab = parseMtab();
|
|
|
+ }
|
|
|
|
|
|
// CPU
|
|
|
|