diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/nodelabels/CommonNodeLabelsManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/nodelabels/CommonNodeLabelsManager.java index c19faaaad3f..7dadaeb3790 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/nodelabels/CommonNodeLabelsManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/nodelabels/CommonNodeLabelsManager.java @@ -95,6 +95,8 @@ public class CommonNodeLabelsManager extends AbstractService { new ConcurrentHashMap(); protected ConcurrentMap nodeCollections = new ConcurrentHashMap(); + private ConcurrentMap isNodeLabelFromHost = + new ConcurrentHashMap(); protected RMNodeLabel noNodeLabel; @@ -603,6 +605,11 @@ public class CommonNodeLabelsManager extends AbstractService { addLabelsToNodeInHost(node, newLabels); } + protected boolean isNodeLabelExplicit(NodeId nodeId) { + return !isNodeLabelFromHost.containsKey(nodeId) || + isNodeLabelFromHost.get(nodeId); + } + @SuppressWarnings("unchecked") protected void internalUpdateLabelsOnNodes( Map> nodeToLabels, NodeLabelUpdateOperation op) @@ -637,6 +644,7 @@ public class CommonNodeLabelsManager extends AbstractService { node.labels.addAll(labels); } addNodeToLabels(node.nodeId, labels); + isNodeLabelFromHost.put(node.nodeId, true); } break; case REPLACE: @@ -646,10 +654,9 @@ public class CommonNodeLabelsManager extends AbstractService { host.labels.addAll(labels); for (Node node : host.nms.values()) { replaceNodeForLabels(node.nodeId, node.labels, labels); - if (node.labels != null) { - replaceLabelsForNode(node.nodeId, node.labels, labels); - } + replaceLabelsForNode(node.nodeId, node.labels, labels); node.labels = null; + isNodeLabelFromHost.put(node.nodeId, true); } break; default: @@ -669,6 +676,7 @@ public class CommonNodeLabelsManager extends AbstractService { nm.labels = new HashSet(); } nm.labels.addAll(labels); + isNodeLabelFromHost.put(nm.nodeId, false); break; case REPLACE: oldLabels = getLabelsByNode(nodeId); @@ -679,6 +687,7 @@ public class CommonNodeLabelsManager extends AbstractService { } nm.labels.clear(); nm.labels.addAll(labels); + isNodeLabelFromHost.put(nm.nodeId, false); break; default: break; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/RMNodeLabelsManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/RMNodeLabelsManager.java index 1a08e03e699..57f5803f9b4 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/RMNodeLabelsManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/nodelabels/RMNodeLabelsManager.java @@ -275,7 +275,7 @@ public class RMNodeLabelsManager extends CommonNodeLabelsManager { Map before = cloneNodeMap(ImmutableSet.of(nodeId)); Node nm = getNMInNodeSet(nodeId); if (null != nm) { - if (null == nm.labels) { + if (isNodeLabelExplicit(nm.nodeId)) { // When node deactivated, remove the nm from node collection if no // labels explicitly set for this particular nm