Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import org.slf4j.LoggerFactory;

import org.apache.hbase.thirdparty.com.google.common.base.Splitter;
import org.apache.hbase.thirdparty.com.google.common.collect.Iterables;
import org.apache.hbase.thirdparty.com.google.common.collect.Iterators;

/**
Expand Down Expand Up @@ -365,10 +366,11 @@ public static String parseHostFromOldLog(Path p) {
return null;
}
try {
String n = p.getName();
int idx = n.lastIndexOf(LOGNAME_SEPARATOR);
String s = URLDecoder.decode(n.substring(0, idx), "UTF8");
return ServerName.valueOf(s).getAddress().toString();
String urlDecodedName = URLDecoder.decode(p.getName(), "UTF8");
Iterable<String> nameSplitsOnComma = Splitter.on(",").split(urlDecodedName);
String host = Iterables.get(nameSplitsOnComma, 0);
String port = Iterables.get(nameSplitsOnComma, 1);
return host + ":" + port;
} catch (Exception e) {
LOG.warn("Skip log file (can't parse): {}", p);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,32 @@ public Path run() {

@Test
public void testFilesystemWalHostNameParsing() throws IOException {
String host = "localhost";
int port = 60030;
ServerName serverName = ServerName.valueOf(host, port, 1234);
String[] hosts =
new String[] { "10.20.30.40", "127.0.0.1", "localhost", "a-region-server.domain.com" };

Path walRootDir = CommonFSUtils.getWALRootDir(conf);
Path oldLogDir = new Path(walRootDir, HConstants.HREGION_OLDLOGDIR_NAME);

Path testWalPath = new Path(oldLogDir,
serverName.toString() + BackupUtils.LOGNAME_SEPARATOR + EnvironmentEdgeManager.currentTime());
Path testMasterWalPath =
new Path(oldLogDir, testWalPath.getName() + MasterRegionFactory.ARCHIVED_WAL_SUFFIX);
int port = 60030;
for (String host : hosts) {
ServerName serverName = ServerName.valueOf(host, port, 1234);

Path testOldWalPath = new Path(oldLogDir,
serverName + BackupUtils.LOGNAME_SEPARATOR + EnvironmentEdgeManager.currentTime());
Assert.assertEquals(host + Addressing.HOSTNAME_PORT_SEPARATOR + port,
BackupUtils.parseHostFromOldLog(testOldWalPath));

Path testMasterWalPath =
new Path(oldLogDir, testOldWalPath.getName() + MasterRegionFactory.ARCHIVED_WAL_SUFFIX);
Assert.assertNull(BackupUtils.parseHostFromOldLog(testMasterWalPath));

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

parsedHost = BackupUtils.parseHostFromOldLog(testWalPath);
Assert.assertEquals(parsedHost, host + Addressing.HOSTNAME_PORT_SEPARATOR + port);
}
}