YARN-10479. Can't remove all node labels after add node label without

nodemanager port, broken by YARN-10647. Contributed by D M Murali Krishna Reddy

(cherry picked from commit 6857a05d6a)
This commit is contained in:
Eric Badger 2021-04-23 23:04:07 +00:00
parent be5fa9615d
commit c7ed492800
2 changed files with 13 additions and 4 deletions

View File

@ -98,6 +98,8 @@ public class CommonNodeLabelsManager extends AbstractService {
new ConcurrentHashMap<String, RMNodeLabel>();
protected ConcurrentMap<String, Host> nodeCollections =
new ConcurrentHashMap<String, Host>();
private ConcurrentMap<NodeId, Boolean> isNodeLabelFromHost =
new ConcurrentHashMap<NodeId, Boolean>();
protected RMNodeLabel noNodeLabel;
@ -604,6 +606,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<NodeId, Set<String>> nodeToLabels, NodeLabelUpdateOperation op)
@ -638,6 +645,7 @@ public class CommonNodeLabelsManager extends AbstractService {
node.labels.addAll(labels);
}
addNodeToLabels(node.nodeId, labels);
isNodeLabelFromHost.put(node.nodeId, true);
}
break;
case REPLACE:
@ -647,10 +655,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:
@ -670,6 +677,7 @@ public class CommonNodeLabelsManager extends AbstractService {
nm.labels = new HashSet<String>();
}
nm.labels.addAll(labels);
isNodeLabelFromHost.put(nm.nodeId, false);
break;
case REPLACE:
oldLabels = getLabelsByNode(nodeId);
@ -680,6 +688,7 @@ public class CommonNodeLabelsManager extends AbstractService {
}
nm.labels.clear();
nm.labels.addAll(labels);
isNodeLabelFromHost.put(nm.nodeId, false);
break;
default:
break;

View File

@ -280,7 +280,7 @@ public class RMNodeLabelsManager extends CommonNodeLabelsManager {
Map<String, Host> 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