Skip to content

Commit aef153d

Browse files
author
mazhengxuan
committed
HBASE-29984 Support separate old WAL directories in backup
1 parent 28808cc commit aef153d

3 files changed

Lines changed: 98 additions & 4 deletions

File tree

hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/impl/IncrementalBackupManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ private List<String> getLogFilesForNewBackup(Map<String, Long> olderTimestamps,
184184
}
185185

186186
// Include the .oldlogs files too.
187-
FileStatus[] oldlogs = fs.listStatus(oldLogDir);
188-
for (FileStatus oldlog : oldlogs) {
189-
p = oldlog.getPath();
190-
currentLogFile = p.toString();
187+
List<String> oldlogs = BackupUtils.getFiles(fs, oldLogDir, new ArrayList<>(), path -> true);
188+
for (String oldlog : oldlogs) {
189+
p = new Path(oldlog);
190+
currentLogFile = oldlog;
191191
if (AbstractFSWALProvider.isMetaFile(p)) {
192192
if (LOG.isDebugEnabled()) {
193193
LOG.debug("Skip .meta log file: " + currentLogFile);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,10 @@ public static String parseHostFromOldLog(Path p) {
332332
if (p.getName().endsWith(MasterRegionFactory.ARCHIVED_WAL_SUFFIX)) {
333333
return null;
334334
}
335+
Path parent = p.getParent();
336+
if (parent != null && ServerName.isFullServerName(parent.getName())) {
337+
return ServerName.valueOf(parent.getName()).getAddress().toString();
338+
}
335339
try {
336340
String urlDecodedName = URLDecoder.decode(p.getName(), "UTF8");
337341
Iterable<String> nameSplitsOnComma = Splitter.on(",").split(urlDecodedName);
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hbase.backup;
19+
20+
import static org.junit.jupiter.api.Assertions.assertNotNull;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
22+
23+
import java.util.List;
24+
import java.util.Map;
25+
import org.apache.hadoop.fs.FileSystem;
26+
import org.apache.hadoop.fs.Path;
27+
import org.apache.hadoop.hbase.HBaseTestingUtil;
28+
import org.apache.hadoop.hbase.ServerName;
29+
import org.apache.hadoop.hbase.TableName;
30+
import org.apache.hadoop.hbase.backup.impl.BackupAdminImpl;
31+
import org.apache.hadoop.hbase.backup.impl.IncrementalBackupManager;
32+
import org.apache.hadoop.hbase.backup.util.BackupUtils;
33+
import org.apache.hadoop.hbase.client.Connection;
34+
import org.apache.hadoop.hbase.client.ConnectionFactory;
35+
import org.apache.hadoop.hbase.testclassification.LargeTests;
36+
import org.apache.hadoop.hbase.util.CommonFSUtils;
37+
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
38+
import org.apache.hadoop.hbase.wal.AbstractFSWALProvider;
39+
import org.junit.jupiter.api.BeforeAll;
40+
import org.junit.jupiter.api.Tag;
41+
import org.junit.jupiter.api.Test;
42+
43+
@Tag(LargeTests.TAG)
44+
public class TestIncrementalBackupManager extends TestBackupBase {
45+
46+
@BeforeAll
47+
public static void setUp() throws Exception {
48+
TEST_UTIL = new HBaseTestingUtil();
49+
conf1 = TEST_UTIL.getConfiguration();
50+
conf1.setBoolean(AbstractFSWALProvider.SEPARATE_OLDLOGDIR, true);
51+
autoRestoreOnFailure = true;
52+
useSecondCluster = false;
53+
setUpHelper();
54+
}
55+
56+
@Test
57+
public void testCollectWALFilesFromRegionServerDirectories() throws Exception {
58+
List<TableName> tables = List.of(table1);
59+
try (Connection conn = ConnectionFactory.createConnection(conf1);
60+
BackupAdminImpl backupAdmin = new BackupAdminImpl(conn)) {
61+
String fullBackupId =
62+
backupAdmin.backupTables(createBackupRequest(BackupType.FULL, tables, BACKUP_ROOT_DIR));
63+
assertTrue(checkSucceeded(fullBackupId));
64+
65+
try (IncrementalBackupManager manager = new IncrementalBackupManager(conn, conf1)) {
66+
BackupInfo backupInfo = manager.createBackupInfo("backup_test", BackupType.INCREMENTAL,
67+
tables, BACKUP_ROOT_DIR, -1, -1, false);
68+
Map<String, Long> previousTimestamps =
69+
BackupUtils.getRSLogTimestampMins(manager.readLogTimestampMap());
70+
ServerName serverName = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0).getServerName();
71+
Long previousTimestamp = previousTimestamps.get(serverName.getAddress().toString());
72+
assertNotNull(previousTimestamp);
73+
74+
TEST_UTIL.waitFor(30_000,
75+
() -> EnvironmentEdgeManager.currentTime() > previousTimestamp + 1);
76+
Path walRootDir = CommonFSUtils.getWALRootDir(conf1);
77+
Path archiveDir = new Path(walRootDir,
78+
AbstractFSWALProvider.getWALArchiveDirectoryName(conf1, serverName.toString()));
79+
Path archivedWAL = new Path(archiveDir, "wal." + (previousTimestamp + 1));
80+
FileSystem fs = walRootDir.getFileSystem(conf1);
81+
fs.mkdirs(archiveDir);
82+
fs.create(archivedWAL).close();
83+
84+
manager.getIncrBackupLogFileMap();
85+
86+
assertTrue(backupInfo.getIncrBackupFileList().contains(archivedWAL.toString()));
87+
}
88+
}
89+
}
90+
}

0 commit comments

Comments
 (0)