Class AbstractPitrRestoreHandler

java.lang.Object
org.apache.hadoop.hbase.backup.impl.AbstractPitrRestoreHandler
Direct Known Subclasses:
CustomBackupLocationPitrRestoreHandler, DefaultPitrRestoreHandler

@Private public abstract class AbstractPitrRestoreHandler extends Object
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 Details

  • Constructor Details

  • Method Details

    • validateAndRestore

      public final void validateAndRestore() throws IOException
      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

      private void validateRequestToTime(long endTime) throws IOException
      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

      private TableName[] resolveTargetTables(TableName[] sourceTables, TableName[] targetTables)
      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 IOException
      Ensures 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 IOException
      Ensures 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 IOException
      Restores 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 RestoreJob MapReduce job that we originally implemented for performing full and incremental backup restores. The MR job (obtained via BackupRestoreFactory.getRestoreJob(Configuration)) is used here to perform an HFile bulk-load of the discovered store files into targetTable.

      Parameters:
      sourceTable - source table name (used for locating bulk files and logging)
      targetTable - destination table to bulk-load the HFiles into
      startTime - start of WAL range (ms)
      endTime - end of WAL range (ms)
      keepOriginalSplits - pass-through flag to control whether original region splits are preserved
      restoreRootDir - 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

      private org.apache.hadoop.util.Tool initializeWalPlayer(long startTime, long endTime)
      Initializes and configures WALPlayer.
    • getBackupMetadata

      Throws:
      IOException