Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ protected int getWeight(Node reader, Node node) {
* @param node Replica of data
* @return weight
*/
private static int getWeightUsingNetworkLocation(Node reader, Node node) {
static int getWeightUsingNetworkLocation(Node reader, Node node) {
//Start off by initializing to Integer.MAX_VALUE
int weight = Integer.MAX_VALUE;
if(reader != null && node != null) {
Expand Down Expand Up @@ -824,7 +824,7 @@ private static int getWeightUsingNetworkLocation(Node reader, Node node) {
currentLevel++;
}
weight = (readerPathToken.length - currentLevel) +
(nodePathToken.length - currentLevel);
(nodePathToken.length - currentLevel) + 2;
}
}
return weight;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.HashMap;
import java.util.List;

import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.math3.stat.inference.ChiSquareTest;
import org.apache.hadoop.conf.Configuration;
import org.junit.Assert;
Expand Down Expand Up @@ -187,4 +188,41 @@ private NodeElement getNewNode(String name, String rackLocation) {
node.setNetworkLocation(rackLocation);
return node;
}

private NodeElement getNewNode(NetworkTopology cluster,
String name, String rackLocation) {
NodeElement node = getNewNode(name, rackLocation);
cluster.add(node);
return node;
}

@Test
@SuppressWarnings("unchecked")
public void testWeights() {
// create the topology
NetworkTopology cluster = NetworkTopology.getInstance(new Configuration());
NodeElement node1 = getNewNode(cluster, "node1", "/r1");
NodeElement node2 = getNewNode(cluster, "node2", "/r1");
NodeElement node3 = getNewNode(cluster, "node3", "/r2");
for (Pair<Integer, NodeElement> test: new Pair[]{Pair.of(0, node1),
Pair.of(2, node2), Pair.of(4, node3)}) {
int expect = test.getLeft();
assertEquals(test.toString(), expect, cluster.getWeight(node1, test.getRight()));
assertEquals(test.toString(), expect,
cluster.getWeightUsingNetworkLocation(node1, test.getRight()));
}
// Reset so that we can have 2 levels
cluster = NetworkTopology.getInstance(new Configuration());
NodeElement node5 = getNewNode(cluster, "node5", "/pod1/r1");
NodeElement node6 = getNewNode(cluster, "node6", "/pod1/r1");
NodeElement node7 = getNewNode(cluster, "node7", "/pod1/r2");
NodeElement node8 = getNewNode(cluster, "node8", "/pod2/r3");
for (Pair<Integer, NodeElement> test: new Pair[]{Pair.of(0, node5),
Pair.of(2, node6), Pair.of(4, node7), Pair.of(6, node8)}) {
int expect = test.getLeft();
assertEquals(test.toString(), expect, cluster.getWeight(node5, test.getRight()));
assertEquals(test.toString(), expect,
cluster.getWeightUsingNetworkLocation(node5, test.getRight()));
}
}
}