diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogUtil.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogUtil.java index f7b1de1159b..95fbda9a8cf 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogUtil.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogUtil.java @@ -159,14 +159,8 @@ public class HLogUtil { return null; } - final String serverName = serverNameAndFile.substring(0, - serverNameAndFile.indexOf('/') - 1); - - if (!ServerName.isFullServerName(serverName)) { - return null; - } - - return ServerName.parseServerName(serverName); + Path p = new Path(path); + return getServerNameFromHLogDirectoryName(p); } /** diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java index c24dfc7f4b8..cfb531b3b35 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java @@ -704,24 +704,31 @@ public class TestHLog { @Test public void testGetServerNameFromHLogDirectoryName() throws IOException { - String hl = FSUtils.getRootDir(conf) + "/"+ - HLogUtil.getHLogDirectoryName(new ServerName("hn", 450, 1398).toString()); + ServerName sn = new ServerName("hn", 450, 1398); + String hl = FSUtils.getRootDir(conf) + "/" + HLogUtil.getHLogDirectoryName(sn.toString()); // Must not throw exception Assert.assertNull(HLogUtil.getServerNameFromHLogDirectoryName(conf, null)); Assert.assertNull(HLogUtil.getServerNameFromHLogDirectoryName(conf, FSUtils.getRootDir(conf).toUri().toString())); - Assert.assertNull( HLogUtil.getServerNameFromHLogDirectoryName(conf, "") ); - Assert.assertNull( HLogUtil.getServerNameFromHLogDirectoryName(conf, " ") ); - Assert.assertNull( HLogUtil.getServerNameFromHLogDirectoryName(conf, hl) ); - Assert.assertNull( HLogUtil.getServerNameFromHLogDirectoryName(conf, hl+"qdf") ); - Assert.assertNull( HLogUtil.getServerNameFromHLogDirectoryName(conf, "sfqf"+hl+"qdf") ); + Assert.assertNull(HLogUtil.getServerNameFromHLogDirectoryName(conf, "")); + Assert.assertNull(HLogUtil.getServerNameFromHLogDirectoryName(conf, " ")); + Assert.assertNull(HLogUtil.getServerNameFromHLogDirectoryName(conf, hl)); + Assert.assertNull(HLogUtil.getServerNameFromHLogDirectoryName(conf, hl + "qdf")); + Assert.assertNull(HLogUtil.getServerNameFromHLogDirectoryName(conf, "sfqf" + hl + "qdf")); - Assert.assertNotNull( HLogUtil.getServerNameFromHLogDirectoryName(conf, - FSUtils.getRootDir(conf).toUri().toString() + - "/.logs/localhost,32984,1343316388997/localhost%2C32984%2C1343316388997.1343316390417" - )); - Assert.assertNotNull( HLogUtil.getServerNameFromHLogDirectoryName(conf, hl+"/qdf") ); + ServerName parsed = HLogUtil.getServerNameFromHLogDirectoryName(conf, + FSUtils.getRootDir(conf).toUri().toString() + + "/.logs/" + sn + "/localhost%2C32984%2C1343316388997.1343316390417"); + Assert.assertEquals("standard", sn, parsed); + + parsed = HLogUtil.getServerNameFromHLogDirectoryName(conf, hl + "/qdf"); + Assert.assertEquals("subdir", sn, parsed); + + parsed = HLogUtil.getServerNameFromHLogDirectoryName(conf, + FSUtils.getRootDir(conf).toUri().toString() + + "/.logs/" + sn + "-splitting/localhost%3A57020.1340474893931"); + Assert.assertEquals("split", sn, parsed); } /**