/** * Sort nodes array by network distance to <i>reader</i>. * <p/> using network location. This is used when the reader * is not a datanode. Sorting the nodes based on network distance * from the reader reduces network traffic and improves * performance. * <p/> * * @param reader Node where data will be read * @param nodes Available replicas with the requested data * @param activeLen Number of active nodes at the front of the array */ public void sortByDistanceUsingNetworkLocation(Node reader, Node[] nodes, int activeLen) { /* * This method is called if the reader is not a datanode, * so nonDataNodeReader flag is set to true. */ sortByDistance(reader, nodes, activeLen, true); }
lb.getLocations(), activeLen); } else { networktopology.sortByDistance(client, lb.getLocations(), activeLen);
/** * Sort nodes array by network distance to <i>reader</i>. * <p/> * In a three-level topology, a node can be either local, on the same rack, * or on a different rack from the reader. Sorting the nodes based on network * distance from the reader reduces network traffic and improves * performance. * <p/> * As an additional twist, we also randomize the nodes at each network * distance. This helps with load balancing when there is data skew. * * @param reader Node where data will be read * @param nodes Available replicas with the requested data * @param activeLen Number of active nodes at the front of the array */ public void sortByDistance(Node reader, Node[] nodes, int activeLen) { /* * This method is called if the reader is a datanode, * so nonDataNodeReader flag is set to false. */ sortByDistance(reader, nodes, activeLen, false); }
topology.sortByDistance(myNode, nodes, nodes.length);
/** * Sort nodes array by their distances to <i>reader</i>. * <p/> * This is the same as {@link NetworkTopology#sortByDistance(Node, Node[], * int)} except with a four-level network topology which contains the * additional network distance of a "node group" which is between local and * same rack. * * @param reader Node where data will be read * @param nodes Available replicas with the requested data * @param activeLen Number of active nodes at the front of the array */ @Override public void sortByDistance(Node reader, Node[] nodes, int activeLen) { // If reader is not a datanode (not in NetworkTopology tree), we need to // replace this reader with a sibling leaf node in tree. if (reader != null && !this.contains(reader)) { Node nodeGroup = getNode(reader.getNetworkLocation()); if (nodeGroup != null && nodeGroup instanceof InnerNode) { InnerNode parentNode = (InnerNode) nodeGroup; // replace reader with the first children of its parent in tree reader = parentNode.getLeaf(0, null); } else { return; } } super.sortByDistance(reader, nodes, activeLen); }
topology.sortByDistance(myNode, readNodes, readNodes.length); for (final MRNflyNode rNode : readNodes) { try {
networktopology.sortByDistance(client, b.getLocations(), activeLen);
networktopology.sortByDistance(client, b.getLocations(), activeLen);
/** * Sort nodes array by their distances to <i>reader</i>. * <p/> * This is the same as {@link NetworkTopology#sortByDistance(Node, Node[], * int)} except with a four-level network topology which contains the * additional network distance of a "node group" which is between local and * same rack. * * @param reader Node where data will be read * @param nodes Available replicas with the requested data * @param activeLen Number of active nodes at the front of the array */ @Override public void sortByDistance(Node reader, Node[] nodes, int activeLen) { // If reader is not a datanode (not in NetworkTopology tree), we need to // replace this reader with a sibling leaf node in tree. if (reader != null && !this.contains(reader)) { Node nodeGroup = getNode(reader.getNetworkLocation()); if (nodeGroup != null && nodeGroup instanceof InnerNode) { InnerNode parentNode = (InnerNode) nodeGroup; // replace reader with the first children of its parent in tree reader = parentNode.getLeaf(0, null); } else { return; } } super.sortByDistance(reader, nodes, activeLen); }
/** * Sort nodes array by their distances to <i>reader</i>. * <p/> * This is the same as {@link NetworkTopology#sortByDistance(Node, Node[], * int)} except with a four-level network topology which contains the * additional network distance of a "node group" which is between local and * same rack. * * @param reader Node where data will be read * @param nodes Available replicas with the requested data * @param activeLen Number of active nodes at the front of the array */ @Override public void sortByDistance(Node reader, Node[] nodes, int activeLen) { // If reader is not a datanode (not in NetworkTopology tree), we need to // replace this reader with a sibling leaf node in tree. if (reader != null && !this.contains(reader)) { Node nodeGroup = getNode(reader.getNetworkLocation()); if (nodeGroup != null && nodeGroup instanceof InnerNode) { InnerNode parentNode = (InnerNode) nodeGroup; // replace reader with the first children of its parent in tree reader = parentNode.getLeaf(0, null); } else { return; } } super.sortByDistance(reader, nodes, activeLen); }
/** * Sort nodes array by their distances to <i>reader</i>. * <p/> * This is the same as {@link NetworkTopology#sortByDistance(Node, Node[], * int)} except with a four-level network topology which contains the * additional network distance of a "node group" which is between local and * same rack. * * @param reader Node where data will be read * @param nodes Available replicas with the requested data * @param activeLen Number of active nodes at the front of the array */ @Override public void sortByDistance(Node reader, Node[] nodes, int activeLen) { // If reader is not a datanode (not in NetworkTopology tree), we need to // replace this reader with a sibling leaf node in tree. if (reader != null && !this.contains(reader)) { Node nodeGroup = getNode(reader.getNetworkLocation()); if (nodeGroup != null && nodeGroup instanceof InnerNode) { InnerNode parentNode = (InnerNode) nodeGroup; // replace reader with the first children of its parent in tree reader = parentNode.getLeaf(0, null); } else { return; } } super.sortByDistance(reader, nodes, activeLen); }
testNodes[2] = dataNodes[0]; cluster.setRandomSeed(0xDEADBEEF); cluster.sortByDistance(dataNodes[0], testNodes, testNodes.length); assertTrue(testNodes[0] == dataNodes[0]); assertTrue(testNodes[1] == dataNodes[1]); dtestNodes[4] = dataNodes[10]; cluster.setRandomSeed(0xDEADBEEF); cluster.sortByDistance(dataNodes[8], dtestNodes, dtestNodes.length - 2); assertTrue(dtestNodes[0] == dataNodes[8]); assertTrue(dtestNodes[1] == dataNodes[11]); testNodes[2] = dataNodes[0]; cluster.setRandomSeed(0xDEADBEEF); cluster.sortByDistance(dataNodes[0], testNodes, testNodes.length); assertTrue(testNodes[0] == dataNodes[0]); assertTrue(testNodes[1] == dataNodes[1]); testNodes[2] = dataNodes[1]; cluster.setRandomSeed(0xDEADBEEF); cluster.sortByDistance(dataNodes[0], testNodes, testNodes.length); assertTrue(testNodes[0] == dataNodes[1]); assertTrue(testNodes[1] == dataNodes[3]); testNodes[2] = dataNodes[3]; cluster.setRandomSeed(0xDEADBEEF); cluster.sortByDistance(dataNodes[0], testNodes, testNodes.length); assertTrue(testNodes[0] == dataNodes[1]); assertTrue(testNodes[1] == dataNodes[3]);