public Integer findNode(DatanodeDescriptor node) { Integer retVal = rackNodesMap.get(node.getHostName()); if (retVal == null) { retVal = rackNodesMap.get(node.getName()); if (retVal == null) { retVal = rackNodesMap.get(node.getHost()); if (retVal == null) { LOG.info("Didn't find " + node.getHostName() + " - " + node.getName() + " - " + node.getHost()); } } } return retVal; } }
/** Check if node is already in the map. */ boolean contains(DatanodeDescriptor node) { if (node==null) { return false; } String host = node.getHost(); hostmapLock.readLock().lock(); try { DatanodeDescriptor[] nodes = map.get(host); if (nodes != null) { for(DatanodeDescriptor containedNode:nodes) { if (node==containedNode) { return true; } } } } finally { hostmapLock.readLock().unlock(); } return false; }
private void resolveNetworkLocation (DatanodeDescriptor node) { List<String> names = new ArrayList<String>(1); if (dnsToSwitchMapping instanceof CachedDNSToSwitchMapping) { // get the node's IP address names.add(node.getHost()); } else { // get the node's host name String hostName = node.getHostName(); int colon = hostName.indexOf(":"); hostName = (colon==-1)?hostName:hostName.substring(0,colon); names.add(hostName); } // resolve its network location List<String> rName = dnsToSwitchMapping.resolve(names); String networkLocation; if (rName == null) { LOG.error("The resolve call returned null! Using " + NetworkTopology.DEFAULT_RACK + " for host " + names); networkLocation = NetworkTopology.DEFAULT_RACK; } else { networkLocation = rName.get(0); } node.setNetworkLocation(networkLocation); }
/** Check if node is already in the map. */ boolean contains(DatanodeDescriptor node) { if (node==null) { return false; } String host = node.getHost(); hostmapLock.readLock().lock(); try { DatanodeDescriptor[] nodes = map.get(host); if (nodes != null) { for(DatanodeDescriptor containedNode:nodes) { if (node==containedNode) { return true; } } } } finally { hostmapLock.readLock().unlock(); } return false; }
mustList.remove(dn.getHost()); mustList.remove(dn.getHostName());
/** add node to the map * return true if the node is added; false otherwise. */ boolean add(DatanodeDescriptor node) { hostmapLock.writeLock().lock(); try { if (node==null || contains(node)) { return false; } String host = node.getHost(); DatanodeDescriptor[] nodes = map.get(host); DatanodeDescriptor[] newNodes; if (nodes==null) { newNodes = new DatanodeDescriptor[1]; newNodes[0]=node; } else { // rare case: more than one datanode on the host newNodes = new DatanodeDescriptor[nodes.length+1]; System.arraycopy(nodes, 0, newNodes, 0, nodes.length); newNodes[nodes.length] = node; } map.put(host, newNodes); return true; } finally { hostmapLock.writeLock().unlock(); } }
mustList.remove(dn.getHost()); mustList.remove(dn.getHostName()); mustList.remove(dn.getHostName() + ":" + dn.getPort());
/** add node to the map * return true if the node is added; false otherwise. */ boolean add(DatanodeDescriptor node) { hostmapLock.writeLock().lock(); try { if (node==null || contains(node)) { return false; } String host = node.getHost(); DatanodeDescriptor[] nodes = map.get(host); DatanodeDescriptor[] newNodes; if (nodes==null) { newNodes = new DatanodeDescriptor[1]; newNodes[0]=node; } else { // rare case: more than one datanode on the host newNodes = new DatanodeDescriptor[nodes.length+1]; System.arraycopy(nodes, 0, newNodes, 0, nodes.length); newNodes[nodes.length] = node; } map.put(host, newNodes); return true; } finally { hostmapLock.writeLock().unlock(); } }
String host = node.getHost(); hostmapLock.writeLock().lock(); try {
String host = node.getHost(); hostmapLock.writeLock().lock(); try {
@Deprecated public String randomDataNode() { int size = datanodeMap.size(); int index = 0; if (size != 0) { index = r.nextInt(size); for(int i=0; i<size; i++) { DatanodeDescriptor d = getDatanodeByIndex(index); if (d != null && !d.isDecommissioned() && !isDatanodeDead(d) && !d.isDecommissionInProgress()) { return d.getHost() + ":" + d.getInfoPort(); } index = (index + 1) % size; } } return null; }
@Deprecated public String randomDataNode() { int size = datanodeMap.size(); int index = 0; if (size != 0) { index = r.nextInt(size); for (int i = 0; i < size; i++) { DatanodeDescriptor d = getDatanodeByIndex(index); if (d != null && !d.isDecommissioned() && !isDatanodeDead(d) && !d.isDecommissionInProgress()) { return d.getHost() + ":" + d.getInfoPort(); } index = (index + 1) % size; } } return null; }
if (((DatanodeDescriptor) rackNode).getHost().equals(info.getHost())) { node = (DatanodeDescriptor) rackNode; break;