HBASE-6746 Impacts of HBASE-6435 vs. HDFS 2.0 trunk

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1382723 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
nkeywal 2012-09-10 09:47:02 +00:00
parent 7fdcc4c87c
commit 293803dcc9
2 changed files with 33 additions and 78 deletions

View File

@ -262,7 +262,8 @@ public class HFileSystem extends FilterFileSystem {
Object[] args) throws Throwable { Object[] args) throws Throwable {
try { try {
Object res = method.invoke(cp, args); Object res = method.invoke(cp, args);
if (res != null && args.length == 3 && "getBlockLocations".equals(method.getName()) if (res != null && args != null && args.length == 3
&& "getBlockLocations".equals(method.getName())
&& res instanceof LocatedBlocks && res instanceof LocatedBlocks
&& args[0] instanceof String && args[0] instanceof String
&& args[0] != null) { && args[0] != null) {

View File

@ -371,88 +371,42 @@ public class TestBlockReorder {
fop.writeDouble(toWrite); fop.writeDouble(toWrite);
fop.close(); fop.close();
for (int i=0; i<10; i++){
// The interceptor is not set in this test, so we get the raw list at this point
LocatedBlocks l;
final long max = System.currentTimeMillis() + 10000;
do {
l = getNamenode(dfs.getClient()).getBlockLocations(fileName, 0, 1);
Assert.assertNotNull(l.getLocatedBlocks());
Assert.assertEquals(l.getLocatedBlocks().size(), 1);
Assert.assertTrue("Expecting " + repCount + " , got " + l.get(0).getLocations().length,
System.currentTimeMillis() < max);
} while (l.get(0).getLocations().length != repCount);
// The interceptor is not set in this test, so we get the raw list at this point // Should be filtered, the name is different => The order won't change
LocatedBlocks l; Object originalList[] = l.getLocatedBlocks().toArray();
final long max = System.currentTimeMillis() + 10000; HFileSystem.ReorderWALBlocks lrb = new HFileSystem.ReorderWALBlocks();
do { lrb.reorderBlocks(conf, l, fileName);
l = getNamenode(dfs.getClient()).getBlockLocations(fileName, 0, 1); Assert.assertArrayEquals(originalList, l.getLocatedBlocks().toArray());
Assert.assertNotNull(l.getLocatedBlocks());
Assert.assertEquals(l.getLocatedBlocks().size(), 1);
Assert.assertTrue("Expecting " + repCount + " , got " + l.get(0).getLocations().length,
System.currentTimeMillis() < max);
} while (l.get(0).getLocations().length != repCount);
// Should be reordered, as we pretend to be a file name with a compliant stuff
Assert.assertNotNull(conf.get(HConstants.HBASE_DIR));
Assert.assertFalse(conf.get(HConstants.HBASE_DIR).isEmpty());
String pseudoLogFile = conf.get(HConstants.HBASE_DIR) + "/" +
HConstants.HREGION_LOGDIR_NAME + "/" + host1 + ",6977,6576" + "/mylogfile";
// Let's fix our own order // Check that it will be possible to extract a ServerName from our construction
setOurOrder(l); Assert.assertNotNull("log= " + pseudoLogFile,
HLog.getServerNameFromHLogDirectoryName(dfs.getConf(), pseudoLogFile));
HFileSystem.ReorderWALBlocks lrb = new HFileSystem.ReorderWALBlocks(); // And check we're doing the right reorder.
// Should be filtered, the name is different lrb.reorderBlocks(conf, l, pseudoLogFile);
lrb.reorderBlocks(conf, l, fileName); Assert.assertEquals(host1, l.get(0).getLocations()[2].getHostName());
checkOurOrder(l);
// Should be reordered, as we pretend to be a file name with a compliant stuff // Check again, it should remain the same.
Assert.assertNotNull(conf.get(HConstants.HBASE_DIR)); lrb.reorderBlocks(conf, l, pseudoLogFile);
Assert.assertFalse(conf.get(HConstants.HBASE_DIR).isEmpty()); Assert.assertEquals(host1, l.get(0).getLocations()[2].getHostName());
String pseudoLogFile = conf.get(HConstants.HBASE_DIR) + "/" + }
HConstants.HREGION_LOGDIR_NAME + "/" + host1 + ",6977,6576" + "/mylogfile";
// Check that it will be possible to extract a ServerName from our construction
Assert.assertNotNull("log= " + pseudoLogFile,
HLog.getServerNameFromHLogDirectoryName(dfs.getConf(), pseudoLogFile));
// And check we're doing the right reorder.
lrb.reorderBlocks(conf, l, pseudoLogFile);
checkOurFixedOrder(l);
// And change again and check again
l.get(0).getLocations()[0].setHostName(host2);
l.get(0).getLocations()[1].setHostName(host1);
l.get(0).getLocations()[2].setHostName(host3);
lrb.reorderBlocks(conf, l, pseudoLogFile);
checkOurFixedOrder(l);
// And change again and check again
l.get(0).getLocations()[0].setHostName(host2);
l.get(0).getLocations()[1].setHostName(host1);
l.get(0).getLocations()[2].setHostName(host3);
lrb.reorderBlocks(conf, l, pseudoLogFile);
checkOurFixedOrder(l);
// nothing to do here, but let's check
l.get(0).getLocations()[0].setHostName(host2);
l.get(0).getLocations()[1].setHostName(host3);
l.get(0).getLocations()[2].setHostName(host1);
lrb.reorderBlocks(conf, l, pseudoLogFile);
checkOurFixedOrder(l);
// nothing to do here, check again
l.get(0).getLocations()[0].setHostName(host2);
l.get(0).getLocations()[1].setHostName(host3);
l.get(0).getLocations()[2].setHostName("nothing");
lrb.reorderBlocks(conf, l, pseudoLogFile);
Assert.assertEquals(host2, l.get(0).getLocations()[0].getHostName());
Assert.assertEquals(host3, l.get(0).getLocations()[1].getHostName());
Assert.assertEquals("nothing", l.get(0).getLocations()[2].getHostName());
}
private void setOurOrder(LocatedBlocks l) {
l.get(0).getLocations()[0].setHostName(host1);
l.get(0).getLocations()[1].setHostName(host2);
l.get(0).getLocations()[2].setHostName(host3);
}
private void checkOurOrder(LocatedBlocks l) {
Assert.assertEquals(host1, l.get(0).getLocations()[0].getHostName());
Assert.assertEquals(host2, l.get(0).getLocations()[1].getHostName());
Assert.assertEquals(host3, l.get(0).getLocations()[2].getHostName());
}
private void checkOurFixedOrder(LocatedBlocks l) {
Assert.assertEquals(host2, l.get(0).getLocations()[0].getHostName());
Assert.assertEquals(host3, l.get(0).getLocations()[1].getHostName());
Assert.assertEquals(host1, l.get(0).getLocations()[2].getHostName());
} }
@org.junit.Rule @org.junit.Rule