Skip to content

Commit

Permalink
HubSpot Backport: HBASE-28082 oldWALs naming can be incompatible with…
Browse files Browse the repository at this point in the history
… HBase backup (apache#5445)

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.

Signed-off-by: Duo Zhang <[email protected]>
  • Loading branch information
janvanbesien-ngdata authored and bbeaudreault committed Apr 1, 2024
1 parent 819605b commit d0fe2b5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
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);
}
}

0 comments on commit d0fe2b5

Please sign in to comment.