@Override public boolean match(NetworkTopology cluster, Node left, Node right) { return cluster.isOnSameRack(left, right); }
if (clusterMap.isOnSameRack(dn0, dn1)) { chooseRemoteRack(1, dn0, excludedNodes, blocksize, maxNodesPerRack, results, avoidStaleNodes, storageTypes);
@Override public boolean match(NetworkTopology cluster, Node left, Node right) { return cluster.isOnSameRack(left, right); }
@Override public boolean match(NetworkTopology cluster, Node left, Node right) { return cluster.isOnSameRack(left, right); }
/** * Returns an integer weight which specifies how far away {node} is away from * {reader}. A lower value signifies that a node is closer. * * @param reader Node where data will be read * @param node Replica of data * @return weight */ protected int getWeight(Node reader, Node node) { // 0 is local, 1 is same rack, 2 is off rack // Start off by initializing to off rack int weight = 2; if (reader != null) { if (reader.equals(node)) { weight = 0; } else if (isOnSameRack(reader, node)) { weight = 1; } } return weight; }
/** * Returns an integer weight which specifies how far away {node} is away from * {reader}. A lower value signifies that a node is closer. * * @param reader Node where data will be read * @param node Replica of data * @return weight */ protected int getWeight(Node reader, Node node) { // 0 is local, 1 is same rack, 2 is off rack // Start off by initializing to off rack int weight = 2; if (reader != null) { if (reader.equals(node)) { weight = 0; } else if (isOnSameRack(reader, node)) { weight = 1; } } return weight; }
/** * Returns an integer weight which specifies how far away {node} is away from * {reader}. A lower value signifies that a node is closer. * * @param reader Node where data will be read * @param node Replica of data * @return weight */ protected int getWeight(Node reader, Node node) { // 0 is local, 1 is same rack, 2 is off rack // Start off by initializing to off rack int weight = 2; if (reader != null) { if (reader.equals(node)) { weight = 0; } else if (isOnSameRack(reader, node)) { weight = 1; } } return weight; }
if (cluster.isOnSameRack(loc.getDatanodeInfo(), targetDN) && addTo(loc)) { return true;
public void testRacks() throws Exception { assertEquals(cluster.getNumOfRacks(), 3); assertTrue(cluster.isOnSameRack(dataNodes[0], dataNodes[1])); assertFalse(cluster.isOnSameRack(dataNodes[1], dataNodes[2])); assertTrue(cluster.isOnSameRack(dataNodes[2], dataNodes[3])); assertTrue(cluster.isOnSameRack(dataNodes[3], dataNodes[4])); assertFalse(cluster.isOnSameRack(dataNodes[4], dataNodes[5])); assertTrue(cluster.isOnSameRack(dataNodes[5], dataNodes[6])); }
/** * all the chosen nodes are on the same rack, choose a node on a new rack for * the next replica according to where the writer is */ private void choose2ndRack(DatanodeDescriptor writer, HashMap<Node, Node> excludedNodes, long blocksize, int maxNodesPerRack, List<DatanodeDescriptor> results) throws NotEnoughReplicasException { if (!clusterMap.isOnSameRack(writer, results.get(0))) { DatanodeDescriptor localNode = chooseLocalNode(writer, excludedNodes, blocksize, maxNodesPerRack, results); if (clusterMap.isOnSameRack(localNode, results.get(0))) { // should not put 2nd replica on the same rack as the first replica results.remove(localNode); } else { return; } } chooseRemoteRack(1, results.get(0), excludedNodes, blocksize, maxNodesPerRack, results); }
/** * Update replication metrics * * @param work record for all scheduled replication */ private void updateReplicationMetrics(List<ReplicationWork> work) { for(ReplicationWork rw : work){ DatanodeDescriptor[] targets = rw.targets; if (targets == null) continue; for (DatanodeDescriptor target : targets) { if (clusterMap.isOnSameRack(rw.srcNode, target)) { myFSMetrics.numLocalRackReplications.inc(); } else { myFSMetrics.numAcrossRackReplications.inc(); } } } } /**
private boolean chooseProxySource() { // check if there is replica which is on the same rack with the target for (BalancerDatanode loc : block.getLocations()) { if (cluster.isOnSameRack(loc.getDatanode(), target.getDatanode())) { if (loc.addPendingBlock(this)) { proxySource = loc; return true; } } } // find out a non-busy replica for (BalancerDatanode loc : block.getLocations()) { if (loc.addPendingBlock(this)) { proxySource = loc; return true; } } return false; }
private boolean chooseProxySource() { // check if there is replica which is on the same rack with the target for (BalancerDatanode loc : block.getLocations()) { if (cluster.isOnSameRack(loc.getDatanode(), target.getDatanode())) { if (loc.addPendingBlock(this)) { proxySource = loc; return true; } } } // find out a non-busy replica for (BalancerDatanode loc : block.getLocations()) { if (loc.addPendingBlock(this)) { proxySource = loc; return true; } } return false; }
private static boolean isOnSameRack(DatanodeStorageInfo left, DatanodeDescriptor right) { return cluster.isOnSameRack(left.getDatanodeDescriptor(), right); }
private boolean isOnSameRack(DatanodeDescriptor left, DatanodeStorageInfo right) { return cluster.isOnSameRack(left, right.getDatanodeDescriptor()); }
/** * This testcase tests re-replication, * when dataNodes[0] and dataNodes[1] are already chosen. * So the 1st replica should be placed on a different rack than rack 1. * the rest replicas can be placed randomly, * @throws Exception */ public void testRereplicate2() throws Exception { List<DatanodeDescriptor> chosenNodes = new ArrayList<DatanodeDescriptor>(); chosenNodes.add(dataNodes[0]); chosenNodes.add(dataNodes[1]); DatanodeDescriptor[] targets; targets = replicator.chooseTarget(filename, 0, dataNodes[0], chosenNodes, BLOCK_SIZE); assertEquals(targets.length, 0); targets = replicator.chooseTarget(filename, 1, dataNodes[0], chosenNodes, BLOCK_SIZE); assertEquals(targets.length, 1); assertFalse(cluster.isOnSameRack(dataNodes[0], targets[0])); targets = replicator.chooseTarget(filename, 2, dataNodes[0], chosenNodes, BLOCK_SIZE); assertEquals(targets.length, 2); assertFalse(cluster.isOnSameRack(dataNodes[0], targets[0])); assertFalse(cluster.isOnSameRack(dataNodes[0], targets[1])); }
1, dataNodes[0], chosenNodes, BLOCK_SIZE); assertEquals(targets.length, 1); assertFalse(cluster.isOnSameRack(dataNodes[0], targets[0])); assertTrue(cluster.isOnSameRack(dataNodes[0], targets[0])); assertFalse(cluster.isOnSameRack(targets[0], targets[1])); assertTrue(cluster.isOnSameRack(dataNodes[0], targets[0])); assertFalse(cluster.isOnSameRack(targets[0], targets[2]));
@Test public void testRacks() throws Exception { assertEquals(cluster.getNumOfRacks(), 6); assertTrue(cluster.isOnSameRack(dataNodes[0], dataNodes[1])); assertFalse(cluster.isOnSameRack(dataNodes[1], dataNodes[2])); assertTrue(cluster.isOnSameRack(dataNodes[2], dataNodes[3])); assertTrue(cluster.isOnSameRack(dataNodes[3], dataNodes[4])); assertFalse(cluster.isOnSameRack(dataNodes[4], dataNodes[5])); assertTrue(cluster.isOnSameRack(dataNodes[5], dataNodes[6])); }
/** * In this testcase, client is is a node outside of file system. * So the 1st replica can be placed on any node. * the 2nd replica should be placed on a different rack, * the 3rd replica should be placed on the same rack as the 2nd replica, * @throws Exception */ public void testChooseTarget5() throws Exception { DatanodeDescriptor[] targets; targets = replicator.chooseTarget(filename, 0, NODE, BLOCK_SIZE); assertEquals(targets.length, 0); targets = replicator.chooseTarget(filename, 1, NODE, BLOCK_SIZE); assertEquals(targets.length, 1); targets = replicator.chooseTarget(filename, 2, NODE, BLOCK_SIZE); assertEquals(targets.length, 2); assertFalse(cluster.isOnSameRack(targets[0], targets[1])); targets = replicator.chooseTarget(filename, 3, NODE, BLOCK_SIZE); assertEquals(targets.length, 3); assertTrue(cluster.isOnSameRack(targets[1], targets[2])); assertFalse(cluster.isOnSameRack(targets[0], targets[1])); }
if (cluster.isOnSameRack(loc.getDatanodeInfo(), targetDN) && addTo(loc)) { return true;