|
@@ -30,6 +30,7 @@ import org.apache.hadoop.conf.Configuration;
|
|
|
import org.apache.hadoop.hdfs.DFSTestUtil;
|
|
|
import org.apache.hadoop.hdfs.TestBlockStoragePolicy;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.NameNode;
|
|
|
+import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
|
import org.junit.Test;
|
|
|
import org.junit.runner.RunWith;
|
|
|
import org.junit.runners.Parameterized;
|
|
@@ -51,6 +52,8 @@ public class TestReplicationPolicyConsiderLoad
|
|
|
|
|
|
@Override
|
|
|
DatanodeDescriptor[] getDatanodeDescriptors(Configuration conf) {
|
|
|
+ conf.setDouble(DFSConfigKeys
|
|
|
+ .DFS_NAMENODE_REPLICATION_CONSIDERLOAD_FACTOR, 1.2);
|
|
|
final String[] racks = {
|
|
|
"/rack1",
|
|
|
"/rack1",
|
|
@@ -124,4 +127,57 @@ public class TestReplicationPolicyConsiderLoad
|
|
|
namenode.getNamesystem().writeUnlock();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testConsiderLoadFactor() throws IOException {
|
|
|
+ namenode.getNamesystem().writeLock();
|
|
|
+ try {
|
|
|
+ dnManager.getHeartbeatManager().updateHeartbeat(dataNodes[0],
|
|
|
+ BlockManagerTestUtil.getStorageReportsForDatanode(dataNodes[0]),
|
|
|
+ dataNodes[0].getCacheCapacity(),
|
|
|
+ dataNodes[0].getCacheUsed(),
|
|
|
+ 5, 0, null);
|
|
|
+ dnManager.getHeartbeatManager().updateHeartbeat(dataNodes[1],
|
|
|
+ BlockManagerTestUtil.getStorageReportsForDatanode(dataNodes[1]),
|
|
|
+ dataNodes[1].getCacheCapacity(),
|
|
|
+ dataNodes[1].getCacheUsed(),
|
|
|
+ 10, 0, null);
|
|
|
+ dnManager.getHeartbeatManager().updateHeartbeat(dataNodes[2],
|
|
|
+ BlockManagerTestUtil.getStorageReportsForDatanode(dataNodes[2]),
|
|
|
+ dataNodes[2].getCacheCapacity(),
|
|
|
+ dataNodes[2].getCacheUsed(),
|
|
|
+ 5, 0, null);
|
|
|
+
|
|
|
+ dnManager.getHeartbeatManager().updateHeartbeat(dataNodes[3],
|
|
|
+ BlockManagerTestUtil.getStorageReportsForDatanode(dataNodes[3]),
|
|
|
+ dataNodes[3].getCacheCapacity(),
|
|
|
+ dataNodes[3].getCacheUsed(),
|
|
|
+ 10, 0, null);
|
|
|
+ dnManager.getHeartbeatManager().updateHeartbeat(dataNodes[4],
|
|
|
+ BlockManagerTestUtil.getStorageReportsForDatanode(dataNodes[4]),
|
|
|
+ dataNodes[4].getCacheCapacity(),
|
|
|
+ dataNodes[4].getCacheUsed(),
|
|
|
+ 15, 0, null);
|
|
|
+ dnManager.getHeartbeatManager().updateHeartbeat(dataNodes[5],
|
|
|
+ BlockManagerTestUtil.getStorageReportsForDatanode(dataNodes[5]),
|
|
|
+ dataNodes[5].getCacheCapacity(),
|
|
|
+ dataNodes[5].getCacheUsed(),
|
|
|
+ 15, 0, null);
|
|
|
+ //Add values in above heartbeats
|
|
|
+ double load = 5 + 10 + 15 + 10 + 15 + 5;
|
|
|
+ // Call chooseTarget()
|
|
|
+ DatanodeDescriptor writerDn = dataNodes[0];
|
|
|
+ DatanodeStorageInfo[] targets = namenode.getNamesystem().getBlockManager()
|
|
|
+ .getBlockPlacementPolicy().chooseTarget("testFile.txt", 3, writerDn,
|
|
|
+ new ArrayList<DatanodeStorageInfo>(), false, null,
|
|
|
+ 1024, TestBlockStoragePolicy.DEFAULT_STORAGE_POLICY);
|
|
|
+ for(DatanodeStorageInfo info : targets) {
|
|
|
+ assertTrue("The node "+info.getDatanodeDescriptor().getName()+
|
|
|
+ " has higher load and should not have been picked!",
|
|
|
+ info.getDatanodeDescriptor().getXceiverCount() <= (load/6)*1.2);
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ namenode.getNamesystem().writeUnlock();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|