Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-29350: Ensure Cleanup of Continuous Backup WALs After Last Backup is Force Deleted#7090
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
73 changes: 69 additions & 4 deletions
73 hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupCommands.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2 hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupSystemTable.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1587,7 +1587,7 @@ private Delete createDeleteForIncrBackupTableSet(String backupRoot) { | ||
| private Delete createDeleteForContinuousBackupTableSet(Set<TableName> tables) { | ||
| Delete delete = new Delete(rowkey(CONTINUOUS_BACKUP_SET)); | ||
| for (TableName tableName : tables) { | ||
| delete.addColumns(META_FAMILY, Bytes.toBytes(tableName.getNameAsString())); | ||
| delete.addColumn(META_FAMILY, Bytes.toBytes(tableName.getNameAsString())); | ||
taklwu marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| return delete; | ||
| } | ||
3 changes: 3 additions & 0 deletions
3 hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/impl/FullTableBackupClient.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 5 additions & 6 deletions
11 hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/TestBackupBase.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 140 additions & 10 deletions
150 hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/TestBackupDeleteWithCleanup.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -18,6 +18,7 @@ | ||
| package org.apache.hadoop.hbase.backup; | ||
| import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.CONF_CONTINUOUS_BACKUP_WAL_DIR; | ||
| import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.CONTINUOUS_BACKUP_REPLICATION_PEER; | ||
| import static org.apache.hadoop.hbase.backup.replication.BackupFileSystemManager.BULKLOAD_FILES_DIR; | ||
| import static org.apache.hadoop.hbase.backup.replication.BackupFileSystemManager.WALS_DIR; | ||
| import static org.apache.hadoop.hbase.backup.replication.ContinuousBackupReplicationEndpoint.DATE_FORMAT; | ||
| @@ -28,18 +29,25 @@ | ||
| import java.io.IOException; | ||
| import java.text.SimpleDateFormat; | ||
| import java.util.ArrayList; | ||
| import java.util.Date; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.fs.FileStatus; | ||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.hbase.HBaseClassTestRule; | ||
| import org.apache.hadoop.hbase.TableName; | ||
| import org.apache.hadoop.hbase.backup.impl.BackupAdminImpl; | ||
| import org.apache.hadoop.hbase.backup.impl.BackupSystemTable; | ||
| import org.apache.hadoop.hbase.backup.replication.BackupFileSystemManager; | ||
| import org.apache.hadoop.hbase.testclassification.LargeTests; | ||
| import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; | ||
| import org.apache.hadoop.util.ToolRunner; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Test; | ||
| import org.junit.experimental.categories.Category; | ||
| @@ -55,38 +63,55 @@ public class TestBackupDeleteWithCleanup extends TestBackupBase { | ||
| String backupWalDirName = "TestBackupDeleteWithCleanup"; | ||
| @Test | ||
| public void testBackupDeleteWithCleanupLogic() throws Exception { | ||
| private FileSystem fs; | ||
| private Path backupWalDir; | ||
| private BackupSystemTable backupSystemTable; | ||
| @Before | ||
| public void setUpTest() throws Exception { | ||
| Path root = TEST_UTIL.getDataTestDirOnTestFS(); | ||
| Path backupWalDir = new Path(root, backupWalDirName); | ||
| backupWalDir = new Path(root, backupWalDirName); | ||
| conf1.set(CONF_CONTINUOUS_BACKUP_WAL_DIR, backupWalDir.toString()); | ||
| FileSystem fs = FileSystem.get(conf1); | ||
| fs = FileSystem.get(conf1); | ||
| fs.mkdirs(backupWalDir); | ||
| backupSystemTable = new BackupSystemTable(TEST_UTIL.getConnection()); | ||
| } | ||
| @After | ||
| public void tearDownTest() throws Exception { | ||
| if (backupSystemTable != null) { | ||
| backupSystemTable.close(); | ||
| } | ||
| if (fs != null && backupWalDir != null) { | ||
| fs.delete(backupWalDir, true); | ||
| } | ||
| EnvironmentEdgeManager.reset(); | ||
| } | ||
| @Test | ||
| public void testBackupDeleteWithCleanupLogic() throws Exception { | ||
| // Step 1: Setup Backup Folders | ||
| long currentTime = EnvironmentEdgeManager.getDelegate().currentTime(); | ||
| setupBackupFolders(fs, backupWalDir, currentTime); | ||
| setupBackupFolders(currentTime); | ||
| // Log the directory structure before cleanup | ||
| logDirectoryStructure(fs, backupWalDir, "Directory structure BEFORE cleanup:"); | ||
| // Step 2: Simulate Backup Creation | ||
| BackupSystemTable backupSystemTable = new BackupSystemTable(TEST_UTIL.getConnection()); | ||
| backupSystemTable.addContinuousBackupTableSet(Set.of(table1), | ||
| currentTime - (2 * ONE_DAY_IN_MILLISECONDS)); | ||
| EnvironmentEdgeManager | ||
| .injectEdge(() -> System.currentTimeMillis() - (2 * ONE_DAY_IN_MILLISECONDS)); | ||
| String backupId = fullTableBackup(Lists.newArrayList(table1)); | ||
| assertTrue(checkSucceeded(backupId)); | ||
| String anotherBackupId = fullTableBackup(Lists.newArrayList(table1)); | ||
| assertTrue(checkSucceeded(anotherBackupId)); | ||
| // Step 3: Run Delete Command | ||
| int ret = | ||
| ToolRunner.run(conf1, new BackupDriver(), new String[] { "delete", "-l", backupId, "-fd" }); | ||
| assertEquals(0, ret); | ||
| deleteBackup(backupId); | ||
| // Log the directory structure after cleanup | ||
| logDirectoryStructure(fs, backupWalDir, "Directory structure AFTER cleanup:"); | ||
| @@ -96,6 +121,70 @@ public void testBackupDeleteWithCleanupLogic() throws Exception { | ||
| // Step 5: Verify System Table Update | ||
| verifySystemTableUpdate(backupSystemTable, currentTime); | ||
| // Cleanup | ||
| deleteBackup(anotherBackupId); | ||
| } | ||
| @Test | ||
| public void testSingleBackupForceDelete() throws Exception { | ||
| // Step 1: Setup Backup Folders | ||
| long currentTime = EnvironmentEdgeManager.getDelegate().currentTime(); | ||
| setupBackupFolders(currentTime); | ||
| // Log the directory structure before cleanup | ||
| logDirectoryStructure(fs, backupWalDir, "Directory structure BEFORE cleanup:"); | ||
| // Step 2: Simulate Backup Creation | ||
taklwu marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| backupSystemTable.addContinuousBackupTableSet(Set.of(table1), | ||
| currentTime - (2 * ONE_DAY_IN_MILLISECONDS)); | ||
| EnvironmentEdgeManager | ||
| .injectEdge(() -> System.currentTimeMillis() - (2 * ONE_DAY_IN_MILLISECONDS)); | ||
| String backupId = fullTableBackupWithContinuous(Lists.newArrayList(table1)); | ||
| assertTrue(checkSucceeded(backupId)); | ||
| assertTrue("Backup replication peer should be enabled after the backup", | ||
| continuousBackupReplicationPeerExistsAndEnabled()); | ||
| // Step 3: Run Delete Command | ||
| deleteBackup(backupId); | ||
| // Log the directory structure after cleanup | ||
| logDirectoryStructure(fs, backupWalDir, "Directory structure AFTER cleanup:"); | ||
| // Step 4: Verify CONTINUOUS_BACKUP_REPLICATION_PEER is disabled | ||
| assertFalse("Backup replication peer should be disabled or removed", | ||
| continuousBackupReplicationPeerExistsAndEnabled()); | ||
| // Step 5: Verify that system table is updated to remove all the tables | ||
| Set<TableName> remainingTables = backupSystemTable.getContinuousBackupTableSet().keySet(); | ||
| assertTrue("System table should have no tables after all full backups are clear", | ||
| remainingTables.isEmpty()); | ||
| // Step 6: Verify that the backup WAL directory is empty | ||
| assertTrue("WAL backup directory should be empty after force delete", | ||
| areWalAndBulkloadDirsEmpty(conf1, backupWalDir.toString())); | ||
| // Step 7: Take new full backup with continuous backup enabled | ||
| String backupIdContinuous = fullTableBackupWithContinuous(Lists.newArrayList(table1)); | ||
| // Step 8: Verify CONTINUOUS_BACKUP_REPLICATION_PEER is enabled again | ||
| assertTrue("Backup replication peer should be re-enabled after new backup", | ||
| continuousBackupReplicationPeerExistsAndEnabled()); | ||
| // And system table has new entry | ||
| Set<TableName> newTables = backupSystemTable.getContinuousBackupTableSet().keySet(); | ||
| assertTrue("System table should contain the table after new backup", | ||
| newTables.contains(table1)); | ||
| // Cleanup | ||
| deleteBackup(backupIdContinuous); | ||
| } | ||
| private void setupBackupFolders(long currentTime) throws IOException { | ||
| setupBackupFolders(fs, backupWalDir, currentTime); | ||
| } | ||
| public static void setupBackupFolders(FileSystem fs, Path backupWalDir, long currentTime) | ||
| @@ -181,4 +270,45 @@ public static void listDirectory(FileSystem fs, Path dir, String indent) throws | ||
| } | ||
| } | ||
| } | ||
| private boolean continuousBackupReplicationPeerExistsAndEnabled() throws IOException { | ||
| return TEST_UTIL.getAdmin().listReplicationPeers().stream().anyMatch( | ||
| peer -> peer.getPeerId().equals(CONTINUOUS_BACKUP_REPLICATION_PEER) && peer.isEnabled()); | ||
| } | ||
| private static boolean areWalAndBulkloadDirsEmpty(Configuration conf, String backupWalDir) | ||
| throws IOException { | ||
| BackupFileSystemManager manager = | ||
| new BackupFileSystemManager(CONTINUOUS_BACKUP_REPLICATION_PEER, conf, backupWalDir); | ||
| FileSystem fs = manager.getBackupFs(); | ||
| Path walDir = manager.getWalsDir(); | ||
| Path bulkloadDir = manager.getBulkLoadFilesDir(); | ||
| return isDirectoryEmpty(fs, walDir) && isDirectoryEmpty(fs, bulkloadDir); | ||
| } | ||
| private static boolean isDirectoryEmpty(FileSystem fs, Path dirPath) throws IOException { | ||
| if (!fs.exists(dirPath)) { | ||
| // Directory doesn't exist — treat as empty | ||
| return true; | ||
| } | ||
| FileStatus[] entries = fs.listStatus(dirPath); | ||
| return entries == null || entries.length == 0; | ||
| } | ||
| private static void deleteBackup(String backupId) throws Exception { | ||
| int ret = | ||
| ToolRunner.run(conf1, new BackupDriver(), new String[] { "delete", "-l", backupId, "-fd" }); | ||
| assertEquals(0, ret); | ||
| } | ||
| private String fullTableBackupWithContinuous(List<TableName> tables) throws IOException { | ||
| try (BackupAdmin admin = new BackupAdminImpl(TEST_UTIL.getConnection())) { | ||
| BackupRequest request = | ||
| createBackupRequest(BackupType.FULL, new ArrayList<>(tables), BACKUP_ROOT_DIR, false, true); | ||
| return admin.backupTables(request); | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.