-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-29521: Update Restore Command to Handle Bulkloaded Files #7300
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
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
72685c8
HBASE-29521: Update Restore Command to Handle Bulkloaded Files
vinayakphegde 5dc7947
address test failures and enhnace the code
vinayakphegde 09d3f06
add new test class TestBulkLoadCollectorJobIntegration
vinayakphegde 5d6becd
refactor the code
vinayakphegde bc3a4ed
Enhance the code quality
vinayakphegde 88244a8
address minor issue
vinayakphegde 7c525eb
address review comments
vinayakphegde 74ed062
fix the error
vinayakphegde ca010c1
address code issue
vinayakphegde File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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 |
|---|---|---|
|
|
@@ -20,8 +20,8 @@ | |
| import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.CONF_CONTINUOUS_BACKUP_PITR_WINDOW_DAYS; | ||
| import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.CONF_CONTINUOUS_BACKUP_WAL_DIR; | ||
| import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.DEFAULT_CONTINUOUS_BACKUP_PITR_WINDOW_DAYS; | ||
| import static org.apache.hadoop.hbase.backup.replication.BackupFileSystemManager.WALS_DIR; | ||
| import static org.apache.hadoop.hbase.backup.replication.ContinuousBackupReplicationEndpoint.ONE_DAY_IN_MILLISECONDS; | ||
| import static org.apache.hadoop.hbase.backup.util.BackupFileSystemManager.WALS_DIR; | ||
| import static org.apache.hadoop.hbase.backup.util.BackupUtils.DATE_FORMAT; | ||
| import static org.apache.hadoop.hbase.mapreduce.WALPlayer.IGNORE_EMPTY_FILES; | ||
|
|
||
|
|
@@ -30,6 +30,7 @@ | |
| import java.text.SimpleDateFormat; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.Date; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
@@ -41,9 +42,12 @@ | |
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.hbase.HBaseConfiguration; | ||
| import org.apache.hadoop.hbase.TableName; | ||
| import org.apache.hadoop.hbase.backup.BackupRestoreFactory; | ||
| import org.apache.hadoop.hbase.backup.PointInTimeRestoreRequest; | ||
| import org.apache.hadoop.hbase.backup.RestoreJob; | ||
| import org.apache.hadoop.hbase.backup.RestoreRequest; | ||
| import org.apache.hadoop.hbase.backup.util.BackupUtils; | ||
| import org.apache.hadoop.hbase.backup.util.BulkFilesCollector; | ||
| import org.apache.hadoop.hbase.client.Connection; | ||
| import org.apache.hadoop.hbase.mapreduce.WALInputFormat; | ||
| import org.apache.hadoop.hbase.mapreduce.WALPlayer; | ||
|
|
@@ -305,6 +309,63 @@ private void restoreTableWithWalReplay(TableName sourceTable, TableName targetTa | |
|
|
||
| backupAdmin.restore(restoreRequest); | ||
| replayWal(sourceTable, targetTable, backupMetadata.getStartTs(), endTime); | ||
|
|
||
| reBulkloadFiles(sourceTable, targetTable, backupMetadata.getStartTs(), endTime, | ||
| request.isKeepOriginalSplits(), request.getRestoreRootDir()); | ||
| } | ||
|
|
||
| /** | ||
| * Re-applies/re-bulkloads store files discovered from WALs into the target table. | ||
| * <p> | ||
| * <b>Note:</b> this method re-uses the same {@link RestoreJob} MapReduce job that we originally | ||
| * implemented for performing full and incremental backup restores. The MR job (obtained via | ||
| * {@link BackupRestoreFactory#getRestoreJob(Configuration)}) is used here to perform an HFile | ||
| * bulk-load of the discovered store files into {@code targetTable}. | ||
| * @param sourceTable source table name (used for locating bulk files and logging) | ||
| * @param targetTable destination table to bulk-load the HFiles into | ||
| * @param startTime start of WAL range (ms) | ||
| * @param endTime end of WAL range (ms) | ||
| * @param keepOriginalSplits pass-through flag to control whether original region splits are | ||
| * preserved | ||
| * @param restoreRootDir local/DFS path under which temporary and output dirs are created | ||
| * @throws IOException on IO or job failure | ||
| */ | ||
| private void reBulkloadFiles(TableName sourceTable, TableName targetTable, long startTime, | ||
| long endTime, boolean keepOriginalSplits, String restoreRootDir) throws IOException { | ||
|
|
||
| Configuration conf = HBaseConfiguration.create(conn.getConfiguration()); | ||
| conf.setBoolean(RestoreJob.KEEP_ORIGINAL_SPLITS_KEY, keepOriginalSplits); | ||
|
|
||
| String walBackupDir = conn.getConfiguration().get(CONF_CONTINUOUS_BACKUP_WAL_DIR); | ||
| Path walDirPath = new Path(walBackupDir); | ||
| conf.set(RestoreJob.BACKUP_ROOT_PATH_KEY, walDirPath.toString()); | ||
|
|
||
| RestoreJob restoreService = BackupRestoreFactory.getRestoreJob(conf); | ||
|
|
||
| List<Path> bulkloadFiles = | ||
| collectBulkFiles(sourceTable, targetTable, startTime, endTime, new Path(restoreRootDir)); | ||
|
|
||
| if (bulkloadFiles.isEmpty()) { | ||
| LOG.info("No bulk-load files found for {} in time range {}-{}. Skipping bulkload restore.", | ||
| sourceTable, startTime, endTime); | ||
| return; | ||
| } | ||
|
|
||
| Path[] pathsArray = bulkloadFiles.toArray(new Path[0]); | ||
|
|
||
| try { | ||
| // Use the existing RestoreJob MR job (the same MapReduce job used for full/incremental | ||
| // restores) | ||
| // to perform the HFile bulk-load of the discovered store files into `targetTable`. | ||
| restoreService.run(pathsArray, new TableName[] { sourceTable }, new Path(restoreRootDir), | ||
| new TableName[] { targetTable }, false); | ||
| LOG.info("Re-bulkload completed for {}", targetTable); | ||
| } catch (Exception e) { | ||
| String errorMessage = | ||
| String.format("Re-bulkload failed for %s: %s", targetTable, e.getMessage()); | ||
| LOG.error(errorMessage, e); | ||
| throw new IOException(errorMessage, e); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -329,6 +390,29 @@ private void replayWal(TableName sourceTable, TableName targetTable, long startT | |
| executeWalReplay(validDirs, sourceTable, targetTable, startTime, endTime); | ||
| } | ||
|
|
||
| private List<Path> collectBulkFiles(TableName sourceTable, TableName targetTable, long startTime, | ||
| long endTime, Path restoreRootDir) throws IOException { | ||
|
|
||
| String walBackupDir = conn.getConfiguration().get(CONF_CONTINUOUS_BACKUP_WAL_DIR); | ||
| Path walDirPath = new Path(walBackupDir); | ||
| LOG.info( | ||
| "Starting WAL bulk-file collection for source: {}, target: {}, time range: {} - {}, WAL backup dir: {}, restore root: {}", | ||
| sourceTable, targetTable, startTime, endTime, walDirPath, restoreRootDir); | ||
|
|
||
| List<String> validDirs = | ||
| getValidWalDirs(conn.getConfiguration(), walDirPath, startTime, endTime); | ||
| if (validDirs.isEmpty()) { | ||
| LOG.warn("No valid WAL directories found for range {} - {}. Skipping bulk-file collection.", | ||
| startTime, endTime); | ||
| return Collections.emptyList(); | ||
| } | ||
|
|
||
| String walDirsCsv = String.join(",", validDirs); | ||
|
|
||
| return BulkFilesCollector.collectFromWalDirs(HBaseConfiguration.create(conn.getConfiguration()), | ||
| walDirsCsv, restoreRootDir, sourceTable, targetTable, startTime, endTime); | ||
| } | ||
|
|
||
| /** | ||
| * Fetches valid WAL directories based on the given time range. | ||
| */ | ||
|
|
@@ -356,7 +440,7 @@ private List<String> getValidWalDirs(Configuration conf, Path walBackupDir, long | |
| validDirs.add(dayDir.getPath().toString()); | ||
| } | ||
| } catch (ParseException e) { | ||
| LOG.warn("Skipping invalid directory name: " + dirName, e); | ||
| LOG.warn("Skipping invalid directory name: {}", dirName, e); | ||
|
||
| } | ||
| } | ||
| return validDirs; | ||
|
|
||
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
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
Oops, something went wrong.
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.
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.
nit:
withKeepOriginalSplitsshould this be configurable ? in what case it should be true?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.
Yes, this should be configurable. But it is hardcoded in the already existing code as well. so, we need to fix in both cases. and I think it should be a separate ticket. But for the moment I added this comment