/** Add a datanode. */ void addDatanode(final DatanodeDescriptor node) { // To keep host2DatanodeMap consistent with datanodeMap, // remove from host2DatanodeMap the datanodeDescriptor removed // from datanodeMap before adding node to host2DatanodeMap. synchronized(this) { host2DatanodeMap.remove(datanodeMap.put(node.getDatanodeUuid(), node)); } networktopology.add(node); // may throw InvalidTopologyException host2DatanodeMap.add(node); checkIfClusterIsNowMultiRack(node); resolveUpgradeDomain(node); if (LOG.isDebugEnabled()) { LOG.debug(getClass().getSimpleName() + ".addDatanode: " + "node " + node + " is added to datanodeMap."); } }
hostmapLock.writeLock().lock(); try { if (node==null || contains(node)) { return false;
/** @return the datanode descriptor for the host. */ public DatanodeDescriptor getDatanodeByHost(final String host) { return host2DatanodeMap.getDatanodeByHost(host); }
@Test public void testRemove() throws Exception { DatanodeDescriptor nodeNotInMap = DFSTestUtil.getDatanodeDescriptor("3.3.3.3", "/d1/r4"); assertFalse(map.remove(nodeNotInMap)); assertTrue(map.remove(dataNodes[0])); assertTrue(map.getDatanodeByHost("1.1.1.1.")==null); assertTrue(map.getDatanodeByHost("2.2.2.2")==dataNodes[1]); DatanodeDescriptor node = map.getDatanodeByHost("3.3.3.3"); assertTrue(node==dataNodes[2] || node==dataNodes[3]); assertNull(map.getDatanodeByHost("4.4.4.4")); assertTrue(map.remove(dataNodes[2])); assertNull(map.getDatanodeByHost("1.1.1.1")); assertEquals(map.getDatanodeByHost("2.2.2.2"), dataNodes[1]); assertEquals(map.getDatanodeByHost("3.3.3.3"), dataNodes[3]); assertTrue(map.remove(dataNodes[3])); assertNull(map.getDatanodeByHost("1.1.1.1")); assertEquals(map.getDatanodeByHost("2.2.2.2"), dataNodes[1]); assertNull(map.getDatanodeByHost("3.3.3.3")); assertFalse(map.remove(null)); assertTrue(map.remove(dataNodes[1])); assertFalse(map.remove(dataNodes[1])); }
/** @return the datanode descriptor for the host. */ public DatanodeDescriptor getDatanodeByXferAddr(String host, int xferPort) { return host2DatanodeMap.getDatanodeByXferAddr(host, xferPort); }
/** Physically remove node from datanodeMap. */ private void wipeDatanode(final DatanodeID node) { final String key = node.getDatanodeUuid(); synchronized (this) { host2DatanodeMap.remove(datanodeMap.remove(key)); } if (LOG.isDebugEnabled()) { LOG.debug(getClass().getSimpleName() + ".wipeDatanode(" + node + "): storage " + key + " is removed from datanodeMap."); } }
@Before public void setup() { dataNodes = new DatanodeDescriptor[] { DFSTestUtil.getDatanodeDescriptor("1.1.1.1", "/d1/r1"), DFSTestUtil.getDatanodeDescriptor("2.2.2.2", "/d1/r1"), DFSTestUtil.getDatanodeDescriptor("3.3.3.3", "/d1/r2"), DFSTestUtil.getDatanodeDescriptor("3.3.3.3", 5021, "/d1/r2"), }; for (DatanodeDescriptor node : dataNodes) { map.add(node); } map.add(null); }
/** * Add all nodes from a dependent nodes list to excludedNodes. * @return number of new excluded nodes */ private int addDependentNodesToExcludedNodes(DatanodeDescriptor chosenNode, Set<Node> excludedNodes) { if (this.host2datanodeMap == null) { return 0; } int countOfExcludedNodes = 0; for(String hostname : chosenNode.getDependentHostNames()) { DatanodeDescriptor node = this.host2datanodeMap.getDataNodeByHostName(hostname); if(node!=null) { if (excludedNodes.add(node)) { countOfExcludedNodes++; } } else { LOG.warn("Not able to find datanode " + hostname + " which has dependency with datanode " + chosenNode.getHostName()); } } return countOfExcludedNodes; }
/** @return the datanode descriptor for the host. */ public DatanodeDescriptor getDatanodeByXferAddr(String host, int xferPort) { return host2DatanodeMap.getDatanodeByXferAddr(host, xferPort); }
/** Physically remove node from datanodeMap. */ private void wipeDatanode(final DatanodeID node) { final String key = node.getDatanodeUuid(); synchronized (datanodeMap) { host2DatanodeMap.remove(datanodeMap.remove(key)); } // Also remove all block invalidation tasks under this node blockManager.removeFromInvalidates(new DatanodeInfo(node)); if (LOG.isDebugEnabled()) { LOG.debug(getClass().getSimpleName() + ".wipeDatanode(" + node + "): storage " + key + " is removed from datanodeMap."); } }
for(int i=0; i<NUM_OF_DATANODES_FOR_DEPENDENCIES; i++) { cluster.add(dataNodesForDependencies[i]); host2DatanodeMap.add(dataNodesForDependencies[i]);
/** * Add all nodes from a dependent nodes list to excludedNodes. * @return number of new excluded nodes */ private int addDependentNodesToExcludedNodes(DatanodeDescriptor chosenNode, Set<Node> excludedNodes) { if (this.host2datanodeMap == null) { return 0; } int countOfExcludedNodes = 0; for(String hostname : chosenNode.getDependentHostNames()) { DatanodeDescriptor node = this.host2datanodeMap.getDataNodeByHostName(hostname); if(node!=null) { if (excludedNodes.add(node)) { countOfExcludedNodes++; } } else { LOG.warn("Not able to find datanode " + hostname + " which has dependency with datanode " + chosenNode.getHostName()); } } return countOfExcludedNodes; }
/** Add a datanode. */ void addDatanode(final DatanodeDescriptor node) { // To keep host2DatanodeMap consistent with datanodeMap, // remove from host2DatanodeMap the datanodeDescriptor removed // from datanodeMap before adding node to host2DatanodeMap. synchronized(datanodeMap) { host2DatanodeMap.remove(datanodeMap.put(node.getDatanodeUuid(), node)); } networktopology.add(node); // may throw InvalidTopologyException host2DatanodeMap.add(node); checkIfClusterIsNowMultiRack(node); if (LOG.isDebugEnabled()) { LOG.debug(getClass().getSimpleName() + ".addDatanode: " + "node " + node + " is added to datanodeMap."); } }
/** get a data node by its hostname. This should be used if only one * datanode service is running on a hostname. If multiple datanodes * are running on a hostname then use methods getDataNodeByXferAddr and * getDataNodeByHostNameAndPort. * @return DatanodeDescriptor if found; otherwise null. */ DatanodeDescriptor getDataNodeByHostName(String hostname) { if(hostname == null) { return null; } hostmapLock.readLock().lock(); try { String ipAddr = mapHost.get(hostname); if(ipAddr == null) { return null; } else { return getDatanodeByHost(ipAddr); } } finally { hostmapLock.readLock().unlock(); } }
hostmapLock.writeLock().lock(); try { if (node==null || contains(node)) { return false;
/** @return the datanode descriptor for the host. */ public DatanodeDescriptor getDatanodeByXferAddr(String host, int xferPort) { return host2DatanodeMap.getDatanodeByXferAddr(host, xferPort); }
/** Physically remove node from datanodeMap. */ private void wipeDatanode(final DatanodeID node) { final String key = node.getDatanodeUuid(); synchronized (datanodeMap) { host2DatanodeMap.remove(datanodeMap.remove(key)); } // Also remove all block invalidation tasks under this node blockManager.removeFromInvalidates(new DatanodeInfo(node)); if (LOG.isDebugEnabled()) { LOG.debug(getClass().getSimpleName() + ".wipeDatanode(" + node + "): storage " + key + " is removed from datanodeMap."); } }
/** * Add all nodes from a dependent nodes list to excludedNodes. * @return number of new excluded nodes */ private int addDependentNodesToExcludedNodes(DatanodeDescriptor chosenNode, Set<Node> excludedNodes) { if (this.host2datanodeMap == null) { return 0; } int countOfExcludedNodes = 0; for(String hostname : chosenNode.getDependentHostNames()) { DatanodeDescriptor node = this.host2datanodeMap.getDataNodeByHostName(hostname); if(node!=null) { if (excludedNodes.add(node)) { countOfExcludedNodes++; } } else { LOG.warn("Not able to find datanode " + hostname + " which has dependency with datanode " + chosenNode.getHostName()); } } return countOfExcludedNodes; }
/** Add a datanode. */ void addDatanode(final DatanodeDescriptor node) { // To keep host2DatanodeMap consistent with datanodeMap, // remove from host2DatanodeMap the datanodeDescriptor removed // from datanodeMap before adding node to host2DatanodeMap. synchronized(datanodeMap) { host2DatanodeMap.remove(datanodeMap.put(node.getDatanodeUuid(), node)); } networktopology.add(node); // may throw InvalidTopologyException host2DatanodeMap.add(node); checkIfClusterIsNowMultiRack(node); if (LOG.isDebugEnabled()) { LOG.debug(getClass().getSimpleName() + ".addDatanode: " + "node " + node + " is added to datanodeMap."); } }
/** @return the datanode descriptor for the host. */ public DatanodeDescriptor getDatanodeByHost(final String host) { return host2DatanodeMap.getDatanodeByHost(host); }