-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-29984 Support separate old WAL directories in backup #8512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -332,6 +332,10 @@ public static String parseHostFromOldLog(Path p) { | |
| if (p.getName().endsWith(MasterRegionFactory.ARCHIVED_WAL_SUFFIX)) { | ||
| return null; | ||
| } | ||
| Path parent = p.getParent(); | ||
| if (parent != null && ServerName.isFullServerName(parent.getName())) { | ||
| return ServerName.valueOf(parent.getName()).getAddress().toString(); | ||
| } | ||
|
Comment on lines
+335
to
+338
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the update. I see That’s helpful, but it doesn’t add an unit test for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added direct coverage in TestBackupUtils. The test constructs |
||
| try { | ||
| String urlDecodedName = URLDecoder.decode(p.getName(), "UTF8"); | ||
| Iterable<String> nameSplitsOnComma = Splitter.on(",").split(urlDecodedName); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.hadoop.hbase.backup; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.hbase.HBaseTestingUtil; | ||
| import org.apache.hadoop.hbase.ServerName; | ||
| import org.apache.hadoop.hbase.TableName; | ||
| import org.apache.hadoop.hbase.backup.impl.BackupAdminImpl; | ||
| import org.apache.hadoop.hbase.backup.impl.IncrementalBackupManager; | ||
| import org.apache.hadoop.hbase.backup.util.BackupUtils; | ||
| import org.apache.hadoop.hbase.client.Connection; | ||
| import org.apache.hadoop.hbase.client.ConnectionFactory; | ||
| import org.apache.hadoop.hbase.testclassification.LargeTests; | ||
| import org.apache.hadoop.hbase.util.CommonFSUtils; | ||
| import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; | ||
| import org.apache.hadoop.hbase.wal.AbstractFSWALProvider; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Tag; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| @Tag(LargeTests.TAG) | ||
| public class TestIncrementalBackupManager extends TestBackupBase { | ||
|
|
||
| @BeforeAll | ||
| public static void setUp() throws Exception { | ||
| TEST_UTIL = new HBaseTestingUtil(); | ||
| conf1 = TEST_UTIL.getConfiguration(); | ||
| conf1.setBoolean(AbstractFSWALProvider.SEPARATE_OLDLOGDIR, true); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: is is possible to have one test for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added The flat and per-RegionServer layouts now share the same test helper: the flat layout uses a WAL filename containing the ServerName, while the separate layout uses a hostless filename under the ServerName directory. Both cases pass. |
||
| autoRestoreOnFailure = true; | ||
| useSecondCluster = false; | ||
| setUpHelper(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCollectWALFilesFromRegionServerDirectories() throws Exception { | ||
| testCollectWALFiles(true); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCollectWALFilesFromFlatOldWALDirectory() throws Exception { | ||
| testCollectWALFiles(false); | ||
| } | ||
|
|
||
| private void testCollectWALFiles(boolean separateOldLogDir) throws Exception { | ||
| Configuration testConf = new Configuration(conf1); | ||
| testConf.setBoolean(AbstractFSWALProvider.SEPARATE_OLDLOGDIR, separateOldLogDir); | ||
| List<TableName> tables = List.of(table1); | ||
| try (Connection conn = ConnectionFactory.createConnection(testConf); | ||
| BackupAdminImpl backupAdmin = new BackupAdminImpl(conn)) { | ||
| String fullBackupId = | ||
| backupAdmin.backupTables(createBackupRequest(BackupType.FULL, tables, BACKUP_ROOT_DIR)); | ||
| assertTrue(checkSucceeded(fullBackupId)); | ||
|
|
||
| try (IncrementalBackupManager manager = new IncrementalBackupManager(conn, testConf)) { | ||
| BackupInfo backupInfo = manager.createBackupInfo("backup_test", BackupType.INCREMENTAL, | ||
| tables, BACKUP_ROOT_DIR, -1, -1, false); | ||
| Map<String, Long> previousTimestamps = | ||
| BackupUtils.getRSLogTimestampMins(manager.readLogTimestampMap()); | ||
| ServerName serverName = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0).getServerName(); | ||
| Long previousTimestamp = previousTimestamps.get(serverName.getAddress().toString()); | ||
| assertNotNull(previousTimestamp); | ||
|
|
||
| TEST_UTIL.waitFor(30_000, | ||
| () -> EnvironmentEdgeManager.currentTime() > previousTimestamp + 1); | ||
| Path walRootDir = CommonFSUtils.getWALRootDir(conf1); | ||
| Path archiveDir = new Path(walRootDir, | ||
| AbstractFSWALProvider.getWALArchiveDirectoryName(testConf, serverName.toString())); | ||
| String walName = (separateOldLogDir ? "wal" : serverName.toString()) | ||
| + BackupUtils.LOGNAME_SEPARATOR + (previousTimestamp + 1); | ||
| Path archivedWAL = new Path(archiveDir, walName); | ||
| FileSystem fs = walRootDir.getFileSystem(conf1); | ||
| fs.mkdirs(archiveDir); | ||
| fs.create(archivedWAL).close(); | ||
|
|
||
| manager.getIncrBackupLogFileMap(); | ||
|
|
||
| assertTrue(backupInfo.getIncrBackupFileList().contains(archivedWAL.toString())); | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you double check if
BackupUtils#parseHostFromOldLogwould need to be changed whenhbase.separate.oldlogdir.by.regionserver=true? basically I checked the logic that whenhbase.separate.oldlogdir.by.regionserver=true, there may have archived file without the host:port but the host name is part of the directory , e.g.oldWALs/10.0.0.1,60030,1700000000000/wal.00000000000000000001There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I double-checked the built-in WAL creation and archive paths.
For the standard WAL providers, enabling hbase.separate.oldlogdir.by.regionserver only changes the archive directory. The WAL filename still normally contains the ServerName because WALFactory uses the ServerName as the WAL prefix and archiving preserves the original filename.
However, parseHostFromOldLog currently ignores the parent directory, so a path such as oldWALs//wal. would return null and the archived WAL would be skipped by incremental backup collection.
I agree that we should handle this problem. I will update parseHostFromOldLog to use a valid full ServerName from the parent directory, falling back to the existing filename parsing for the flat oldWAL layout, and adjust the regression test to cover a hostless WAL filename.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BackupUtils.parseHostFromOldLog now checks whether the parent directory is a full ServerName and uses it to derive host:port. The existing filename parsing is retained as the fallback for the flat oldWAL layout.
I also updated TestIncrementalBackupManager to use oldWALs//wal., so the regression test now covers the hostless WAL filename case directly.
TestBackupUtils and TestIncrementalBackupManager both pass.