Skip to content

Commit 5152a34

Browse files
janvanbesien-ngdatawchevreuil
authored andcommitted
HBASE-28082 oldWALs naming can be incompatible with 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]> (cherry picked from commit 9262cbc)
1 parent 7f093d3 commit 5152a34

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