Skip to content

Commit 14da0f8

Browse files
HBASE-28082 more lenient WAL hostname parsing
Make the hostname parsing in BackupUtils#parseHostFromOldLog more lenient by not making any assumptions about the name of the file other than that it starts with a org.apache.hadoop.hbase.ServerName.
1 parent 9f6ec47 commit 14da0f8

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/util/BackupUtils.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import org.slf4j.LoggerFactory;
6666

6767
import org.apache.hbase.thirdparty.com.google.common.base.Splitter;
68+
import org.apache.hbase.thirdparty.com.google.common.collect.Iterables;
6869
import org.apache.hbase.thirdparty.com.google.common.collect.Iterators;
6970

7071
/**
@@ -365,10 +366,11 @@ public static String parseHostFromOldLog(Path p) {
365366
return null;
366367
}
367368
try {
368-
String n = p.getName();
369-
int idx = n.lastIndexOf(LOGNAME_SEPARATOR);
370-
String s = URLDecoder.decode(n.substring(0, idx), "UTF8");
371-
return ServerName.valueOf(s).getAddress().toString();
369+
String urlDecodedName = URLDecoder.decode(p.getName(), "UTF8");
370+
Iterable<String> nameSplitsOnComma = Splitter.on(",").split(urlDecodedName);
371+
String host = Iterables.get(nameSplitsOnComma, 0);
372+
String port = Iterables.get(nameSplitsOnComma, 1);
373+
return host + ":" + port;
372374
} catch (Exception e) {
373375
LOG.warn("Skip log file (can't parse): {}", p);
374376
return null;

hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/TestBackupUtils.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,32 @@ public Path run() {
8787

8888
@Test
8989
public void testFilesystemWalHostNameParsing() throws IOException {
90-
String host = "localhost";
91-
int port = 60030;
92-
ServerName serverName = ServerName.valueOf(host, port, 1234);
90+
String[] hosts =
91+
new String[] { "10.20.30.40", "127.0.0.1", "localhost", "a-region-server.domain.com" };
92+
9393
Path walRootDir = CommonFSUtils.getWALRootDir(conf);
9494
Path oldLogDir = new Path(walRootDir, HConstants.HREGION_OLDLOGDIR_NAME);
9595

96-
Path testWalPath = new Path(oldLogDir,
97-
serverName.toString() + BackupUtils.LOGNAME_SEPARATOR + EnvironmentEdgeManager.currentTime());
98-
Path testMasterWalPath =
99-
new Path(oldLogDir, testWalPath.getName() + MasterRegionFactory.ARCHIVED_WAL_SUFFIX);
96+
int port = 60030;
97+
for (String host : hosts) {
98+
ServerName serverName = ServerName.valueOf(host, port, 1234);
99+
100+
Path testOldWalPath = new Path(oldLogDir,
101+
serverName + BackupUtils.LOGNAME_SEPARATOR + EnvironmentEdgeManager.currentTime());
102+
Assert.assertEquals(host + Addressing.HOSTNAME_PORT_SEPARATOR + port,
103+
BackupUtils.parseHostFromOldLog(testOldWalPath));
104+
105+
Path testMasterWalPath =
106+
new Path(oldLogDir, testOldWalPath.getName() + MasterRegionFactory.ARCHIVED_WAL_SUFFIX);
107+
Assert.assertNull(BackupUtils.parseHostFromOldLog(testMasterWalPath));
100108

101-
String parsedHost = BackupUtils.parseHostFromOldLog(testMasterWalPath);
102-
Assert.assertNull(parsedHost);
109+
// org.apache.hadoop.hbase.wal.BoundedGroupingStrategy does this
110+
Path testOldWalWithRegionGroupingPath = new Path(oldLogDir,
111+
serverName + BackupUtils.LOGNAME_SEPARATOR + serverName + BackupUtils.LOGNAME_SEPARATOR
112+
+ "regiongroup-0" + BackupUtils.LOGNAME_SEPARATOR + EnvironmentEdgeManager.currentTime());
113+
Assert.assertEquals(host + Addressing.HOSTNAME_PORT_SEPARATOR + port,
114+
BackupUtils.parseHostFromOldLog(testOldWalWithRegionGroupingPath));
115+
}
103116

104-
parsedHost = BackupUtils.parseHostFromOldLog(testWalPath);
105-
Assert.assertEquals(parsedHost, host + Addressing.HOSTNAME_PORT_SEPARATOR + port);
106117
}
107118
}

0 commit comments

Comments
 (0)