Class AbstractPitrRestoreHandler
java.lang.Object
org.apache.hadoop.hbase.backup.impl.AbstractPitrRestoreHandler
- Direct Known Subclasses:
CustomBackupLocationPitrRestoreHandler,DefaultPitrRestoreHandler
Abstract base class for handling Point-In-Time Restore (PITR).
Defines the common PITR algorithm using the Template Method Pattern. Subclasses provide the metadata source (e.g., backup system table or a custom backup location).
The PITR flow includes:
- Validating recovery time within the PITR window
- Checking for continuous backup and valid backup availability
- Restoring the backup
- Replaying WALs to bring tables to the target state
Subclasses must implement getBackupMetadata(PointInTimeRestoreRequest) to supply the
list of completed backups.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final BackupAdminImplprotected final Connectionprivate static final org.slf4j.Loggerprotected final PointInTimeRestoreRequest -
Constructor Summary
ConstructorsConstructorDescriptionAbstractPitrRestoreHandler(Connection conn, PointInTimeRestoreRequest request) -
Method Summary
Modifier and TypeMethodDescriptionprivate booleancanPerformPitr(TableName stableName, TableName tTableName, long endTime, Map<TableName, Long> continuousBackupTables, List<PitrBackupMetadata> backups) Checks whether PITR can be performed for a given source-target table pair.private voidexecuteWalReplay(List<String> walDirs, TableName sourceTable, TableName targetTable, long startTime, long endTime) Executes WAL replay using WALPlayer.protected abstract List<PitrBackupMetadata>private PitrBackupMetadatagetValidBackup(TableName sTableName, TableName tTablename, long endTime, Map<TableName, Long> continuousBackupTables, List<PitrBackupMetadata> backups) Finds and returns the first valid backup metadata entry that can be used to restore the given source table up to the specified end time.private org.apache.hadoop.util.ToolinitializeWalPlayer(long startTime, long endTime) Initializes and configures WALPlayer.private booleanisValidBackupForPitr(PitrBackupMetadata backupMetadata, TableName tableName, long endTime, Map<TableName, Long> continuousBackupTables) Determines if the given backup is valid for PITR.private voidreBulkloadFiles(TableName sourceTable, TableName targetTable, long startTime, long endTime, boolean keepOriginalSplits, String restoreRootDir) Re-applies/re-bulkloads store files discovered from WALs into the target table.private voidReplays WALs to bring the table to the desired state.private TableName[]resolveTargetTables(TableName[] sourceTables, TableName[] targetTables) Resolves the target table array.private voidrestoreTableWithWalReplay(TableName sourceTable, TableName targetTable, long endTime, Map<TableName, Long> continuousBackupTables, List<PitrBackupMetadata> backupMetadataList, PointInTimeRestoreRequest request) Restores the table using the selected backup and replays WALs from the backup start time to the requested end time.final voidValidates the PITR request and performs the restore if valid.private voidvalidateBackupAvailability(TableName[] sTableArray, TableName[] tTableArray, long endTime, Map<TableName, Long> continuousBackupTables, List<PitrBackupMetadata> backups) Ensures that a valid backup and corresponding WALs exist for PITR for each source table.private voidvalidateContinuousBackup(TableName[] tables, Map<TableName, Long> continuousBackupTables) Ensures that all source tables have continuous backup enabled.private voidvalidatePitr(long endTime, TableName[] sTableArray, TableName[] tTableArray) Validates whether Point-In-Time Recovery (PITR) is possible for the given tables at the specified time.private voidvalidateRequestToTime(long endTime) Validates whether the requested end time falls within the allowed PITR recovery window.
-
Field Details
-
LOG
-
conn
-
backupAdmin
-
request
-
-
Constructor Details
-
AbstractPitrRestoreHandler
AbstractPitrRestoreHandler(Connection conn, PointInTimeRestoreRequest request)
-
-
Method Details
-
validateAndRestore
Validates the PITR request and performs the restore if valid. This is the main entry point for the PITR process and should be called by clients.- Throws:
IOException
-
validateRequestToTime
Validates whether the requested end time falls within the allowed PITR recovery window.- Parameters:
endTime- The target recovery time.- Throws:
IOException- If the requested recovery time is outside the allowed window.
-
resolveTargetTables
Resolves the target table array. If null or empty, defaults to the source table array. -
validatePitr
private void validatePitr(long endTime, TableName[] sTableArray, TableName[] tTableArray) throws IOException Validates whether Point-In-Time Recovery (PITR) is possible for the given tables at the specified time.PITR requires:
- Continuous backup to be enabled for the source tables.
- A valid backup image and corresponding WALs to be available.
- Parameters:
endTime- The target recovery time.sTableArray- The source tables to restore.tTableArray- The target tables where the restore will be performed.- Throws:
IOException- If PITR is not possible due to missing continuous backup or backup images.
-
validateContinuousBackup
private void validateContinuousBackup(TableName[] tables, Map<TableName, Long> continuousBackupTables) throws IOExceptionEnsures that all source tables have continuous backup enabled.- Throws:
IOException
-
validateBackupAvailability
private void validateBackupAvailability(TableName[] sTableArray, TableName[] tTableArray, long endTime, Map<TableName, Long> continuousBackupTables, List<PitrBackupMetadata> backups) throws IOExceptionEnsures that a valid backup and corresponding WALs exist for PITR for each source table. PITR requires: 1. A valid backup available before the end time. 2. Write-Ahead Logs (WALs) covering the remaining duration up to the end time.- Throws:
IOException
-
canPerformPitr
private boolean canPerformPitr(TableName stableName, TableName tTableName, long endTime, Map<TableName, Long> continuousBackupTables, List<PitrBackupMetadata> backups) Checks whether PITR can be performed for a given source-target table pair. -
getValidBackup
private PitrBackupMetadata getValidBackup(TableName sTableName, TableName tTablename, long endTime, Map<TableName, Long> continuousBackupTables, List<PitrBackupMetadata> backups) Finds and returns the first valid backup metadata entry that can be used to restore the given source table up to the specified end time. A backup is considered valid if:- It contains the source table
- It was completed before the requested end time
- Its start time is after the table's continuous backup start time
- It passes the restore request validation
-
isValidBackupForPitr
private boolean isValidBackupForPitr(PitrBackupMetadata backupMetadata, TableName tableName, long endTime, Map<TableName, Long> continuousBackupTables) Determines if the given backup is valid for PITR.A backup is valid if:
- It contains the source table.
- It was completed before the end time.
- The start timestamp of the backup is after the continuous backup start time for the table.
- Parameters:
backupMetadata- Backup information object.tableName- Table to check.endTime- The target recovery time.continuousBackupTables- Map of tables with continuous backup enabled.- Returns:
- true if the backup is valid for PITR, false otherwise.
-
restoreTableWithWalReplay
private void restoreTableWithWalReplay(TableName sourceTable, TableName targetTable, long endTime, Map<TableName, Long> continuousBackupTables, List<PitrBackupMetadata> backupMetadataList, PointInTimeRestoreRequest request) throws IOExceptionRestores the table using the selected backup and replays WALs from the backup start time to the requested end time.- Throws:
IOException- if no valid backup is found or WAL replay fails
-
reBulkloadFiles
private void reBulkloadFiles(TableName sourceTable, TableName targetTable, long startTime, long endTime, boolean keepOriginalSplits, String restoreRootDir) throws IOException Re-applies/re-bulkloads store files discovered from WALs into the target table.Note: this method re-uses the same
RestoreJobMapReduce job that we originally implemented for performing full and incremental backup restores. The MR job (obtained viaBackupRestoreFactory.getRestoreJob(Configuration)) is used here to perform an HFile bulk-load of the discovered store files intotargetTable.- Parameters:
sourceTable- source table name (used for locating bulk files and logging)targetTable- destination table to bulk-load the HFiles intostartTime- start of WAL range (ms)endTime- end of WAL range (ms)keepOriginalSplits- pass-through flag to control whether original region splits are preservedrestoreRootDir- local/DFS path under which temporary and output dirs are created- Throws:
IOException- on IO or job failure
-
replayWal
private void replayWal(TableName sourceTable, TableName targetTable, long startTime, long endTime) throws IOException Replays WALs to bring the table to the desired state.- Throws:
IOException
-
executeWalReplay
private void executeWalReplay(List<String> walDirs, TableName sourceTable, TableName targetTable, long startTime, long endTime) throws IOException Executes WAL replay using WALPlayer.- Throws:
IOException
-
initializeWalPlayer
Initializes and configures WALPlayer. -
getBackupMetadata
protected abstract List<PitrBackupMetadata> getBackupMetadata(PointInTimeRestoreRequest request) throws IOException - Throws:
IOException
-