From 81bbee685275b0a015489ad27464c88d8b250875 Mon Sep 17 00:00:00 2001 From: Jian He Date: Tue, 14 Apr 2015 10:54:22 -0700 Subject: [PATCH] YARN-3266. RMContext#inactiveNodes should have NodeId as map key. Contributed by Chengbing Liu (cherry picked from commit b46ee1e7a31007985b88072d9af3d97c33a261a7) --- hadoop-yarn-project/CHANGES.txt | 3 ++ .../RMActiveServiceContext.java | 6 +-- .../server/resourcemanager/RMContext.java | 2 +- .../server/resourcemanager/RMContextImpl.java | 2 +- .../resourcemanager/rmnode/RMNodeImpl.java | 10 ++-- .../resourcemanager/webapp/RMWebServices.java | 2 +- .../TestRMNodeTransitions.java | 53 +++++++++++++++++-- .../resourcemanager/webapp/TestRMWebApp.java | 6 +-- .../webapp/TestRMWebServicesNodes.java | 9 ++-- 9 files changed, 72 insertions(+), 21 deletions(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 72390033d00..478d0aebacc 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -144,6 +144,9 @@ Release 2.8.0 - UNRELEASED YARN-3472. Fixed possible leak in DelegationTokenRenewer#allTokens. (Rohith Sharmaks via jianhe) + YARN-3266. RMContext#inactiveNodes should have NodeId as map key. + (Chengbing Liu via jianhe) + Release 2.7.1 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/RMActiveServiceContext.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/RMActiveServiceContext.java index 03fc40ed2c5..e4c72d8fb34 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/RMActiveServiceContext.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/RMActiveServiceContext.java @@ -68,8 +68,8 @@ public class RMActiveServiceContext { private final ConcurrentMap nodes = new ConcurrentHashMap(); - private final ConcurrentMap inactiveNodes = - new ConcurrentHashMap(); + private final ConcurrentMap inactiveNodes = + new ConcurrentHashMap(); private final ConcurrentMap systemCredentials = new ConcurrentHashMap(); @@ -185,7 +185,7 @@ public class RMActiveServiceContext { @Private @Unstable - public ConcurrentMap getInactiveRMNodes() { + public ConcurrentMap getInactiveRMNodes() { return this.inactiveNodes; } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/RMContext.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/RMContext.java index ecf61667e7c..bc50268276f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/RMContext.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/RMContext.java @@ -61,7 +61,7 @@ public interface RMContext { ConcurrentMap getSystemCredentialsForApps(); - ConcurrentMap getInactiveRMNodes(); + ConcurrentMap getInactiveRMNodes(); ConcurrentMap getRMNodes(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/RMContextImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/RMContextImpl.java index 1d0d6c0bf8a..2f9209c9c43 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/RMContextImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/RMContextImpl.java @@ -149,7 +149,7 @@ public class RMContextImpl implements RMContext { } @Override - public ConcurrentMap getInactiveRMNodes() { + public ConcurrentMap getInactiveRMNodes() { return activeServiceContext.getInactiveRMNodes(); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmnode/RMNodeImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmnode/RMNodeImpl.java index ace2cf7983d..3be1867c9a7 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmnode/RMNodeImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmnode/RMNodeImpl.java @@ -524,11 +524,11 @@ public class RMNodeImpl implements RMNode, EventHandler { RMNodeStartedEvent startEvent = (RMNodeStartedEvent) event; List containers = null; - String host = rmNode.nodeId.getHost(); - if (rmNode.context.getInactiveRMNodes().containsKey(host)) { + NodeId nodeId = rmNode.nodeId; + if (rmNode.context.getInactiveRMNodes().containsKey(nodeId)) { // Old node rejoining - RMNode previouRMNode = rmNode.context.getInactiveRMNodes().get(host); - rmNode.context.getInactiveRMNodes().remove(host); + RMNode previouRMNode = rmNode.context.getInactiveRMNodes().get(nodeId); + rmNode.context.getInactiveRMNodes().remove(nodeId); rmNode.updateMetricsForRejoinedNode(previouRMNode.getState()); } else { // Increment activeNodes explicitly because this is a new node. @@ -737,7 +737,7 @@ public class RMNodeImpl implements RMNode, EventHandler { rmNode.context.getRMNodes().remove(rmNode.nodeId); LOG.info("Deactivating Node " + rmNode.nodeId + " as it is now " + finalState); - rmNode.context.getInactiveRMNodes().put(rmNode.nodeId.getHost(), rmNode); + rmNode.context.getInactiveRMNodes().put(rmNode.nodeId, rmNode); //Update the metrics rmNode.updateMetricsForDeactivatedNode(initialState, finalState); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebServices.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebServices.java index 8c63d279a0a..967fbf19763 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebServices.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/RMWebServices.java @@ -320,7 +320,7 @@ public class RMWebServices { RMNode ni = this.rm.getRMContext().getRMNodes().get(nid); boolean isInactive = false; if (ni == null) { - ni = this.rm.getRMContext().getInactiveRMNodes().get(nid.getHost()); + ni = this.rm.getRMContext().getInactiveRMNodes().get(nid); if (ni == null) { throw new NotFoundException("nodeId, " + nodeId + ", is not found"); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMNodeTransitions.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMNodeTransitions.java index c6da3fd1fe8..fb9d2ef6c26 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMNodeTransitions.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMNodeTransitions.java @@ -306,6 +306,47 @@ public class TestRMNodeTransitions { Assert.assertEquals(NodeState.LOST, node.getState()); } + @Test + public void testRunningExpireMultiple() { + RMNodeImpl node1 = getRunningNode(null, 10001); + RMNodeImpl node2 = getRunningNode(null, 10002); + ClusterMetrics cm = ClusterMetrics.getMetrics(); + int initialActive = cm.getNumActiveNMs(); + int initialLost = cm.getNumLostNMs(); + int initialUnhealthy = cm.getUnhealthyNMs(); + int initialDecommissioned = cm.getNumDecommisionedNMs(); + int initialRebooted = cm.getNumRebootedNMs(); + node1.handle(new RMNodeEvent(node1.getNodeID(), RMNodeEventType.EXPIRE)); + Assert.assertEquals("Active Nodes", initialActive - 1, cm.getNumActiveNMs()); + Assert.assertEquals("Lost Nodes", initialLost + 1, cm.getNumLostNMs()); + Assert.assertEquals("Unhealthy Nodes", initialUnhealthy, + cm.getUnhealthyNMs()); + Assert.assertEquals("Decommissioned Nodes", initialDecommissioned, + cm.getNumDecommisionedNMs()); + Assert.assertEquals("Rebooted Nodes", initialRebooted, + cm.getNumRebootedNMs()); + Assert.assertEquals(NodeState.LOST, node1.getState()); + Assert.assertTrue("Node " + node1.toString() + " should be inactive", + rmContext.getInactiveRMNodes().containsKey(node1.getNodeID())); + Assert.assertFalse("Node " + node2.toString() + " should not be inactive", + rmContext.getInactiveRMNodes().containsKey(node2.getNodeID())); + + node2.handle(new RMNodeEvent(node1.getNodeID(), RMNodeEventType.EXPIRE)); + Assert.assertEquals("Active Nodes", initialActive - 2, cm.getNumActiveNMs()); + Assert.assertEquals("Lost Nodes", initialLost + 2, cm.getNumLostNMs()); + Assert.assertEquals("Unhealthy Nodes", initialUnhealthy, + cm.getUnhealthyNMs()); + Assert.assertEquals("Decommissioned Nodes", initialDecommissioned, + cm.getNumDecommisionedNMs()); + Assert.assertEquals("Rebooted Nodes", initialRebooted, + cm.getNumRebootedNMs()); + Assert.assertEquals(NodeState.LOST, node2.getState()); + Assert.assertTrue("Node " + node1.toString() + " should be inactive", + rmContext.getInactiveRMNodes().containsKey(node1.getNodeID())); + Assert.assertTrue("Node " + node2.toString() + " should be inactive", + rmContext.getInactiveRMNodes().containsKey(node2.getNodeID())); + } + @Test public void testUnhealthyExpire() { RMNodeImpl node = getUnhealthyNode(); @@ -458,14 +499,18 @@ public class TestRMNodeTransitions { } private RMNodeImpl getRunningNode() { - return getRunningNode(null); + return getRunningNode(null, 0); } private RMNodeImpl getRunningNode(String nmVersion) { - NodeId nodeId = BuilderUtils.newNodeId("localhost", 0); + return getRunningNode(nmVersion, 0); + } + + private RMNodeImpl getRunningNode(String nmVersion, int port) { + NodeId nodeId = BuilderUtils.newNodeId("localhost", port); Resource capability = Resource.newInstance(4096, 4); - RMNodeImpl node = new RMNodeImpl(nodeId, rmContext,null, 0, 0, - null, capability, nmVersion); + RMNodeImpl node = new RMNodeImpl(nodeId, rmContext, null, 0, 0, null, + capability, nmVersion); node.handle(new RMNodeStartedEvent(node.getNodeID(), null, null)); Assert.assertEquals(NodeState.RUNNING, node.getState()); return node; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebApp.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebApp.java index 481a53b6221..02904217060 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebApp.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebApp.java @@ -173,10 +173,10 @@ public class TestRMWebApp { final List deactivatedNodes = MockNodes.deactivatedNodes(racks, numNodes, newResource(mbsPerNode)); - final ConcurrentMap deactivatedNodesMap = + final ConcurrentMap deactivatedNodesMap = Maps.newConcurrentMap(); for (RMNode node : deactivatedNodes) { - deactivatedNodesMap.put(node.getHostName(), node); + deactivatedNodesMap.put(node.getNodeID(), node); } RMContextImpl rmContext = new RMContextImpl(null, null, null, null, @@ -186,7 +186,7 @@ public class TestRMWebApp { return applicationsMaps; } @Override - public ConcurrentMap getInactiveRMNodes() { + public ConcurrentMap getInactiveRMNodes() { return deactivatedNodesMap; } @Override diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesNodes.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesNodes.java index f507e1789f7..ec20bba55d1 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesNodes.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesNodes.java @@ -32,6 +32,7 @@ import javax.xml.parsers.DocumentBuilderFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.yarn.api.records.ContainerStatus; +import org.apache.hadoop.yarn.api.records.NodeId; import org.apache.hadoop.yarn.api.records.NodeState; import org.apache.hadoop.yarn.server.api.records.NodeHealthStatus; import org.apache.hadoop.yarn.server.resourcemanager.MockNM; @@ -263,8 +264,9 @@ public class TestRMWebServicesNodes extends JerseyTestBase { assertEquals("incorrect number of elements", 2, nodeArray.length()); for (int i = 0; i < nodeArray.length(); ++i) { JSONObject info = nodeArray.getJSONObject(i); - String host = info.get("id").toString().split(":")[0]; - RMNode rmNode = rm.getRMContext().getInactiveRMNodes().get(host); + String[] node = info.get("id").toString().split(":"); + NodeId nodeId = NodeId.newInstance(node[0], Integer.parseInt(node[1])); + RMNode rmNode = rm.getRMContext().getInactiveRMNodes().get(nodeId); WebServicesTestUtils.checkStringMatch("nodeHTTPAddress", "", info.getString("nodeHTTPAddress")); WebServicesTestUtils.checkStringMatch("state", rmNode.getState() @@ -295,7 +297,8 @@ public class TestRMWebServicesNodes extends JerseyTestBase { assertEquals("Incorrect Node Information.", "h2:1234", id); - RMNode rmNode = rm.getRMContext().getInactiveRMNodes().get("h2"); + NodeId nodeId = NodeId.newInstance("h2", 1234); + RMNode rmNode = rm.getRMContext().getInactiveRMNodes().get(nodeId); WebServicesTestUtils.checkStringMatch("nodeHTTPAddress", "", info.getString("nodeHTTPAddress")); WebServicesTestUtils.checkStringMatch("state",