@Override protected DatanodeDescriptor chooseDataNode(final String scope, final Collection<Node> excludedNode, StorageType type) { // only the code that uses DFSNetworkTopology should trigger this code path. Preconditions.checkArgument(clusterMap instanceof DFSNetworkTopology); DFSNetworkTopology dfsClusterMap = (DFSNetworkTopology)clusterMap; DatanodeDescriptor a = (DatanodeDescriptor) dfsClusterMap .chooseRandomWithStorageType(scope, excludedNode, type); DatanodeDescriptor b = (DatanodeDescriptor) dfsClusterMap .chooseRandomWithStorageType(scope, excludedNode, type); return select(a, b); }
/** * Choose a datanode from the given <i>scope</i> with specified * storage type. * @return the chosen node, if there is any. */ protected DatanodeDescriptor chooseDataNode(final String scope, final Collection<Node> excludedNodes, StorageType type) { return (DatanodeDescriptor) ((DFSNetworkTopology) clusterMap) .chooseRandomWithStorageTypeTwoTrial(scope, excludedNodes, type); }
public static DFSNetworkTopology getInstance(Configuration conf) { DFSNetworkTopology nt = ReflectionUtils.newInstance(conf.getClass( DFSConfigKeys.DFS_NET_TOPOLOGY_IMPL_KEY, DFSConfigKeys.DFS_NET_TOPOLOGY_IMPL_DEFAULT, DFSNetworkTopology.class), conf); return (DFSNetworkTopology) nt.init(DFSTopologyNodeImpl.FACTORY); }
Node n = chooseRandom(searchScope, excludedScope, excludedNodes); if (n == null) { if (LOG.isDebugEnabled()) { return chooseRandomWithStorageType(searchScope, excludedScope, excludedNodes, type);
getEligibleChildren(root, excludeRoot, type); if (candidates.size() == 0) { return null; chosenNode = chooseRandomWithStorageTypeAndExcludeRoot( nextRoot, excludeRoot, type);
Node node = getNode(scope); if (node == null) { LOG.debug("Invalid scope {}, non-existing node", scope); Node excludeRoot = excludedScope == null ? null : getNode(excludedScope); DatanodeDescriptor dn = (DatanodeDescriptor)getNode(nodeLocation); availableCount -= dn.hasStorageType(type)? 1 : 0; } else { chosen = chooseRandomWithStorageTypeAndExcludeRoot(root, excludeRoot, type); if (excludedNodes == null || !excludedNodes.contains(chosen)) {
DFSConfigKeys.DFS_USE_DFS_NETWORK_TOPOLOGY_DEFAULT); if (useDfsNetworkTopology) { networktopology = DFSNetworkTopology.getInstance(conf); } else { networktopology = NetworkTopology.getInstance(conf);
/** * Randomly choose one node from <i>scope</i>, with specified storage type. * * If scope starts with ~, choose one from the all nodes except for the * ones in <i>scope</i>; otherwise, choose one from <i>scope</i>. * If excludedNodes is given, choose a node that's not in excludedNodes. * * @param scope range of nodes from which a node will be chosen * @param excludedNodes nodes to be excluded from * @param type the storage type we search for * @return the chosen node */ public Node chooseRandomWithStorageType(final String scope, final Collection<Node> excludedNodes, StorageType type) { netlock.readLock().lock(); try { if (scope.startsWith("~")) { return chooseRandomWithStorageType( NodeBase.ROOT, scope.substring(1), excludedNodes, type); } else { return chooseRandomWithStorageType( scope, null, excludedNodes, type); } } finally { netlock.readLock().unlock(); } }