/** * Randomly choose a node. * * @param scope range of nodes from which a node will be chosen * @return the chosen node * * @see #chooseRandom(String, Collection) */ public Node chooseRandom(final String scope) { return chooseRandom(scope, null); }
/** * Randomly choose one node from <i>scope</i>. * * 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 * @return the chosen node */ public Node chooseRandom(final String scope, final Collection<Node> excludedNodes) { netlock.readLock().lock(); try { if (scope.startsWith("~")) { return chooseRandom(NodeBase.ROOT, scope.substring(1), excludedNodes); } else { return chooseRandom(scope, null, excludedNodes); } } finally { netlock.readLock().unlock(); } }
Node ret = null; if (availableNodes > 0) { ret = chooseRandom(innerNode, node, excludedNodes, numOfDatanodes, availableNodes);
/** * Choose a datanode from the given <i>scope</i>. * @return the chosen node, if there is any. */ protected DatanodeDescriptor chooseDataNode(final String scope, final Collection<Node> excludedNodes) { return (DatanodeDescriptor) clusterMap.chooseRandom(scope, excludedNodes); }
@Override protected DatanodeDescriptor chooseDataNode(final String scope, final Collection<Node> excludedNode) { DatanodeDescriptor a = (DatanodeDescriptor) clusterMap.chooseRandom(scope, excludedNode); DatanodeDescriptor b = (DatanodeDescriptor) clusterMap.chooseRandom(scope, excludedNode); return select(a, b); }
.chooseRandom(NodeBase.ROOT);
).chooseRandom(NodeBase.ROOT, excludes);
/** * Choose a datanode from the given <i>scope</i>. * @return the chosen node, if there is any. */ protected DatanodeDescriptor chooseDataNode(final String scope) { return (DatanodeDescriptor) clusterMap.chooseRandom(scope); }
/** * Choose a datanode from the given <i>scope</i>. * @return the chosen node, if there is any. */ protected DatanodeDescriptor chooseDataNode(final String scope) { return (DatanodeDescriptor) clusterMap.chooseRandom(scope); }
/** randomly choose one node from <i>scope</i> * 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> * @param scope range of nodes from which a node will be chosen * @return the chosen node */ public Node chooseRandom(String scope) { netlock.readLock().lock(); try { if (scope.startsWith("~")) { return chooseRandom(NodeBase.ROOT, scope.substring(1)); } else { return chooseRandom(scope, null); } } finally { netlock.readLock().unlock(); } }
@Override protected DatanodeDescriptor chooseDataNode(String scope) { DatanodeDescriptor a = (DatanodeDescriptor) clusterMap.chooseRandom(scope); DatanodeDescriptor b = (DatanodeDescriptor) clusterMap.chooseRandom(scope); if (a != null && b != null){ int ret = compareDataNode(a, b); if (ret == 0) { return a; } else if (ret < 0) { return (RAND.nextInt(100) < balancedPreference) ? a : b; } else { return (RAND.nextInt(100) < balancedPreference) ? b : a; } } else { return a == null ? b : a; } }
/** randomly choose one node from <i>scope</i> * 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> * @param scope range of nodes from which a node will be chosen * @return the chosen node */ public Node chooseRandom(String scope) { netlock.readLock().lock(); try { if (scope.startsWith("~")) { return chooseRandom(NodeBase.ROOT, scope.substring(1)); } else { return chooseRandom(scope, null); } } finally { netlock.readLock().unlock(); } }
/** randomly choose one node from <i>scope</i> * 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> * @param scope range of nodes from which a node will be choosen * @return the choosen node */ public Node chooseRandom(String scope) { netlock.readLock().lock(); try { if (scope.startsWith("~")) { return chooseRandom(NodeBase.ROOT, scope.substring(1)); } else { return chooseRandom(scope, null); } } finally { netlock.readLock().unlock(); } }
/** randomly choose one node from <i>scope</i> * 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> * @param scope range of nodes from which a node will be chosen * @return the chosen node */ public Node chooseRandom(String scope) { netlock.readLock().lock(); try { if (scope.startsWith("~")) { return chooseRandom(NodeBase.ROOT, scope.substring(1)); } else { return chooseRandom(scope, null); } } finally { netlock.readLock().unlock(); } }
/** randomly choose one node from <i>scope</i> * 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> * @param scope range of nodes from which a node will be choosen * @return the choosen node */ public Node chooseRandom(String scope) { netlock.readLock().lock(); try { if (scope.startsWith("~")) { return chooseRandom(NodeBase.ROOT, scope.substring(1)); } else { return chooseRandom(scope, null); } } finally { netlock.readLock().unlock(); } }
/** randomly choose one node from <i>scope</i> * 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> * @param scope range of nodes from which a node will be chosen * @return the chosen node */ public Node chooseRandom(String scope) { netlock.readLock().lock(); try { if (scope.startsWith("~")) { return chooseRandom(NodeBase.ROOT, scope.substring(1)); } else { return chooseRandom(scope, null); } } finally { netlock.readLock().unlock(); } }
@Override protected DatanodeDescriptor chooseDataNode(String scope) { DatanodeDescriptor a = (DatanodeDescriptor) clusterMap.chooseRandom(scope); DatanodeDescriptor b = (DatanodeDescriptor) clusterMap.chooseRandom(scope); if (a != null && b != null){ int ret = compareDataNode(a, b); if (ret == 0) { return a; } else if (ret < 0) { return (RAND.nextInt(100) < balancedPreference) ? a : b; } else { return (RAND.nextInt(100) < balancedPreference) ? b : a; } } else { return a == null ? b : a; } }
/** * This picks a large number of nodes at random in order to ensure coverage * * @param numNodes the number of nodes * @param excludedScope the excluded scope * @return the frequency that nodes were chosen */ private Map<Node, Integer> pickNodesAtRandom(int numNodes, String excludedScope) { Map<Node, Integer> frequency = new HashMap<Node, Integer>(); for (DatanodeDescriptor dnd : dataNodes) { frequency.put(dnd, 0); } for (int j = 0; j < numNodes; j++) { Node random = cluster.chooseRandom(excludedScope); frequency.put(random, frequency.get(random) + 1); } return frequency; }
/** @return a randomly chosen datanode. */ static DatanodeDescriptor getRandomDatanode(final NameNode namenode) { return (DatanodeDescriptor)namenode.getNamesystem().getBlockManager( ).getDatanodeManager().getNetworkTopology().chooseRandom( NodeBase.ROOT); } }
/** @return a randomly chosen datanode. */ static DatanodeDescriptor getRandomDatanode(final NameNode namenode) { return (DatanodeDescriptor)namenode.getNamesystem().getBlockManager( ).getDatanodeManager().getNetworkTopology().chooseRandom( NodeBase.ROOT); } }