From 293803dcc9be0e4c433ed3033563e59d4ac389a2 Mon Sep 17 00:00:00 2001 From: nkeywal Date: Mon, 10 Sep 2012 09:47:02 +0000 Subject: [PATCH] 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 --- .../apache/hadoop/hbase/fs/HFileSystem.java | 3 +- .../hadoop/hbase/fs/TestBlockReorder.java | 108 +++++------------- 2 files changed, 33 insertions(+), 78 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/fs/HFileSystem.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/fs/HFileSystem.java index d3be2c3ef3b..dcc692e0d6d 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/fs/HFileSystem.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/fs/HFileSystem.java @@ -262,7 +262,8 @@ public class HFileSystem extends FilterFileSystem { Object[] args) throws Throwable { try { 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 && args[0] instanceof String && args[0] != null) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorder.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorder.java index 726f28bc244..b1a2abdf5db 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorder.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/fs/TestBlockReorder.java @@ -371,88 +371,42 @@ public class TestBlockReorder { fop.writeDouble(toWrite); 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 - 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); + // Should be filtered, the name is different => The order won't change + Object originalList[] = l.getLocatedBlocks().toArray(); + HFileSystem.ReorderWALBlocks lrb = new HFileSystem.ReorderWALBlocks(); + lrb.reorderBlocks(conf, l, fileName); + Assert.assertArrayEquals(originalList, l.getLocatedBlocks().toArray()); + // 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 - setOurOrder(l); + // Check that it will be possible to extract a ServerName from our construction + Assert.assertNotNull("log= " + pseudoLogFile, + HLog.getServerNameFromHLogDirectoryName(dfs.getConf(), pseudoLogFile)); - HFileSystem.ReorderWALBlocks lrb = new HFileSystem.ReorderWALBlocks(); - // Should be filtered, the name is different - lrb.reorderBlocks(conf, l, fileName); - checkOurOrder(l); + // And check we're doing the right reorder. + lrb.reorderBlocks(conf, l, pseudoLogFile); + Assert.assertEquals(host1, l.get(0).getLocations()[2].getHostName()); - // 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"; - - // 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()); + // Check again, it should remain the same. + lrb.reorderBlocks(conf, l, pseudoLogFile); + Assert.assertEquals(host1, l.get(0).getLocations()[2].getHostName()); + } } @org.junit.Rule