Package org.apache.hadoop.hbase.backup
Class IntegrationTestBackupRestoreBase
java.lang.Object
org.apache.hadoop.hbase.util.AbstractHBaseTool
org.apache.hadoop.hbase.IntegrationTestBase
org.apache.hadoop.hbase.backup.IntegrationTestBackupRestoreBase
- All Implemented Interfaces:
org.apache.hadoop.conf.Configurable,org.apache.hadoop.util.Tool
- Direct Known Subclasses:
IntegrationTestBackupRestore,IntegrationTestContinuousBackupRestore
An abstract base class that is used to run backup, restore, and delete integration tests. This
class performs both full backups and incremental backups. Both continuous backup and
non-continuous backup test cases are supported. The number of incremental backups performed
depends on the number of iterations defined by the user. The class performs the backup/restore in
a separate thread, where one thread is created per table. The number of tables is user-defined,
along with other various configurations.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classNested classes/interfaces inherited from class org.apache.hadoop.hbase.util.AbstractHBaseTool
org.apache.hadoop.hbase.util.AbstractHBaseTool.OptionsOrderComparator -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected static final Stringprotected static Stringprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected org.apache.hadoop.fs.FileSystemprotected static final org.slf4j.Loggerprotected static final Stringprotected static final Stringprotected intprotected intprotected static final Stringprotected intprotected static final Stringprotected intprotected static final Stringprotected intprotected static final longprotected static final Stringprotected longprotected static org.apache.hadoop.hbase.TableName[]Fields inherited from class org.apache.hadoop.hbase.IntegrationTestBase
CHAOS_MONKEY_PROPS, monkey, MONKEY_LONG_OPT, monkeyProps, monkeyToUse, NO_CLUSTER_CLEANUP_LONG_OPT, noClusterCleanUp, utilFields inherited from class org.apache.hadoop.hbase.util.AbstractHBaseTool
cmdLineArgs, conf, EXIT_FAILURE, EXIT_SUCCESS, LONG_HELP_OPTION, options, SHORT_HELP_OPTION -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprivate booleanareAllTimestampsPastThreshold(Map<org.apache.hadoop.hbase.ServerName, Long> timestamps, long threshold, org.apache.hadoop.hbase.TableName tableName) Checks if all timestamps in a map with ServerName and timestamp key-values pairs are past the provided timestamp threshold.private Stringbackup(org.apache.hadoop.hbase.backup.BackupRequest request, org.apache.hadoop.hbase.backup.BackupAdmin client, List<String> backupIds) protected booleancheckSucceeded(String backupId) Returns status of backupprivate voidprotected voidCreates a directory specified by backupWALDir and sets this directory to CONF_CONTINUOUS_BACKUP_WAL_DIR in the configuration.org.apache.hadoop.hbase.backup.RestoreRequestcreateRestoreRequest(String backupRootDir, String backupId, boolean check, org.apache.hadoop.hbase.TableName[] fromTables, org.apache.hadoop.hbase.TableName[] toTables, boolean isOverwrite) Get restore request.private voidcreateTable(org.apache.hadoop.hbase.TableName tableName) protected voidcreateTables(String tableBaseName) private voidprivate voiddeleteMostRecentIncrementalBackup(List<String> backupIds, org.apache.hadoop.hbase.backup.BackupAdmin client) Performs the delete command for the most recently taken incremental backup, and also removes this backup from the list of backup IDs.private voidprivate String[]getAllIncrementalBackupIds(List<String> backupIds) Uses the list of all backup IDs to return a sublist of incremental backup IDs.private org.apache.hadoop.hbase.backup.BackupInfogetBackupInfo(String backupId) Provides the name of the CFs that are protected from random Chaos monkey activity (alter)private longgetLatestPutTimestamp(org.apache.hadoop.hbase.client.Table table) Scans the backed-up table and returns the timestamp (ms) of the latest Put operation on the table.org.apache.hadoop.hbase.TableNameProvides the name of the table that is protected from random Chaos monkey activityprotected voidThis method is useful for ensuring important test parameters are initialized when running integration tests in IntelliJ or in the command line with Maven.private voidloadData(org.apache.hadoop.hbase.TableName table, int numRows) private voidprotected voidprocessOptions(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine cmd) private voidremoveNonexistentBackups(List<String> backupIds) private voidrestore(org.apache.hadoop.hbase.backup.RestoreRequest request, org.apache.hadoop.hbase.backup.BackupAdmin client) private voidrestoreTableAndVerifyRowCount(org.apache.hadoop.hbase.client.Connection conn, org.apache.hadoop.hbase.backup.BackupAdmin client, org.apache.hadoop.hbase.TableName table, String backupId, long expectedRows) Restores a table using the provided backup ID and ensure the table has the correct row count afterprotected voidrunTestMulti(boolean isContinuousBackupEnabled) This is the main driver method used by tests that extend this abstract base class.private voidrunTestSingle(org.apache.hadoop.hbase.TableName tableName, boolean isContinuousBackupEnabled) This method is what performs the actual backup, restore, merge, and delete operations.voidvoidvoidtearDown()private voidverifyAllBackupsExist(List<String> backupIds) Verifies all backups in the list of backup IDs actually exist on the filesystem.private voidverifyBackupDoesNotExist(String backupId) private voidverifyBackupExistenceAfterMerge(List<String> backupIds) Iterates through the list of backups and verifies the full backup and latest incremental backup still exist, while also verifying all other backups no longer exist.private voidverifyBackupExists(String backupId) private voidverifyBackupWALFiles(org.apache.hadoop.fs.Path walPartitionDir) Verifies the WAL partition directory contains a backup WAL file.private voidverifyNoBackupsExist(List<String> backupIds) Verifies zero backups in the list of backup IDs exist on the filesystem.private voidverifySnapshotExists(org.apache.hadoop.hbase.TableName tableName, String backupId) Verifies a snapshot's "data.manifest" file exists after a full backup has been performed for a table.private org.apache.hadoop.fs.PathverifyWALPartitionDirExists(org.apache.hadoop.fs.Path backupWALs) Waits for a WAL partition directory to exist inside the backup WAL directory.private org.apache.hadoop.fs.PathVerifies the .../backupWALDir/WALs directory exists and returns its Pathprivate voidwaitForCheckpointTimestampsToUpdate(org.apache.hadoop.hbase.client.Connection conn, long latestPutTimestamp, org.apache.hadoop.hbase.TableName tableName) Waits for the replication checkpoint timestamp of each region server to meet or pass the timestamp of the latest Put operation on the backed-up table.Methods inherited from class org.apache.hadoop.hbase.IntegrationTestBase
cleanUp, cleanUpCluster, cleanUpMonkey, cleanUpMonkey, doWork, getConf, getDefaultMonkeyFactory, getTestingUtil, loadMonkeyProperties, processBaseOptions, runTestFromCommandLine, setUp, startMonkeyMethods inherited from class org.apache.hadoop.hbase.util.AbstractHBaseTool
addOption, addOptNoArg, addOptNoArg, addOptWithArg, addOptWithArg, addRequiredOption, addRequiredOptWithArg, addRequiredOptWithArg, doStaticMain, getOptionAsDouble, getOptionAsInt, getOptionAsInt, getOptionAsLong, getOptionAsLong, newParser, parseArgs, parseInt, parseLong, printUsage, printUsage, processOldArgs, run, setConf
-
Field Details
-
LOG
-
NUMBER_OF_TABLES_KEY
- See Also:
-
COLUMN_NAME
- See Also:
-
REGION_COUNT_KEY
- See Also:
-
REGIONSERVER_COUNT_KEY
- See Also:
-
ROWS_PER_ITERATION_KEY
- See Also:
-
NUM_ITERATIONS_KEY
- See Also:
-
DEFAULT_REGION_COUNT
- See Also:
-
DEFAULT_REGIONSERVER_COUNT
- See Also:
-
DEFAULT_NUMBER_OF_TABLES
- See Also:
-
DEFAULT_NUM_ITERATIONS
- See Also:
-
DEFAULT_ROWS_IN_ITERATION
- See Also:
-
SLEEP_TIME_KEY
- See Also:
-
SLEEP_TIME_DEFAULT
- See Also:
-
DEFAULT_BACKUP_ROOT_DIR
-
rowsInIteration
-
regionsCountPerServer
-
regionServerCount
-
numIterations
-
numTables
-
sleepTime
-
tableNames
-
fs
-
backupRootDir
-
-
Constructor Details
-
IntegrationTestBackupRestoreBase
public IntegrationTestBackupRestoreBase()
-
-
Method Details
-
tearDown
- Throws:
IOException
-
setUpMonkey
- Overrides:
setUpMonkeyin classIntegrationTestBase- Throws:
Exception
-
deleteTablesIfAny
- Throws:
IOException
-
createTables
- Throws:
Exception
-
createAndSetBackupWalDir
Creates a directory specified by backupWALDir and sets this directory to CONF_CONTINUOUS_BACKUP_WAL_DIR in the configuration.- Throws:
IOException
-
cleanUpBackupDir
- Throws:
IOException
-
runTestMulti
This is the main driver method used by tests that extend this abstract base class. This method starts one backup and restore thread per table.- Parameters:
isContinuousBackupEnabled- Boolean flag used to specify if the backups should have continuous backup enabled.
-
runTestSingle
private void runTestSingle(org.apache.hadoop.hbase.TableName tableName, boolean isContinuousBackupEnabled) throws IOException, InterruptedException This method is what performs the actual backup, restore, merge, and delete operations. This method is run in a separate thread. It first performs a full backup. After, it iteratively performs a series of incremental backups and restores. Later, it deletes the backups.- Parameters:
tableName- The table the backups are performed onisContinuousBackupEnabled- Boolean flag used to indicate if the backups should have continuous backup enabled.- Throws:
IOExceptionInterruptedException
-
createTable
- Throws:
Exception
-
loadData
- Throws:
IOException
-
backup
private String backup(org.apache.hadoop.hbase.backup.BackupRequest request, org.apache.hadoop.hbase.backup.BackupAdmin client, List<String> backupIds) throws IOException - Throws:
IOException
-
restore
private void restore(org.apache.hadoop.hbase.backup.RestoreRequest request, org.apache.hadoop.hbase.backup.BackupAdmin client) throws IOException - Throws:
IOException
-
merge
private void merge(String[] backupIds, org.apache.hadoop.hbase.backup.BackupAdmin client) throws IOException - Throws:
IOException
-
delete
private void delete(String[] backupIds, org.apache.hadoop.hbase.backup.BackupAdmin client) throws IOException - Throws:
IOException
-
verifySnapshotExists
private void verifySnapshotExists(org.apache.hadoop.hbase.TableName tableName, String backupId) throws IOException Verifies a snapshot's "data.manifest" file exists after a full backup has been performed for a table. The "data.manifest" file's path will look like the following: .../backupRootDir/backup_1760572298945/default/TABLE_NAME/.hbase-snapshot/ snapshot_1760572306407_default_TABLE_NAME/data.manifest- Throws:
IOException
-
verifyWALsDirectoryExists
Verifies the .../backupWALDir/WALs directory exists and returns its Path- Throws:
IOException
-
verifyWALPartitionDirExists
private org.apache.hadoop.fs.Path verifyWALPartitionDirExists(org.apache.hadoop.fs.Path backupWALs) throws IOException, InterruptedException Waits for a WAL partition directory to exist inside the backup WAL directory. The directory should be something like: .../backupWALDir/WALs/2025-10-17. The directory's existence is either eventually asserted, or an assertion error is thrown if it does not exist past the wait deadline. This verification is to be used for full backups with continuous backup enabled.- Parameters:
backupWALs- The directory that should contain the partition directory. i.e. .../backupWALDir/WALs- Returns:
- The Path to the WAL partition directory
- Throws:
IOExceptionInterruptedException
-
verifyBackupWALFiles
Verifies the WAL partition directory contains a backup WAL file. The WAL file's path will look something like the following: .../backupWALDir/WALs/2025-10-17/wal_file.1760738249595.1880be89-0b69-4bad-8d0e-acbf25c63b7e- Parameters:
walPartitionDir- The date directory for a backup WAL i.e. .../backupWALDir/WALs/2025-10-17- Throws:
IOException
-
areAllTimestampsPastThreshold
private boolean areAllTimestampsPastThreshold(Map<org.apache.hadoop.hbase.ServerName, Long> timestamps, long threshold, org.apache.hadoop.hbase.TableName tableName) Checks if all timestamps in a map with ServerName and timestamp key-values pairs are past the provided timestamp threshold.- Parameters:
timestamps- Map with ServerName and timestamp key-value pairsthreshold- Timestamp to check all timestamp values in the map against- Returns:
- True if all timestamps values in the map have met or are path the timestamp threshold; False otherwise
-
waitForCheckpointTimestampsToUpdate
private void waitForCheckpointTimestampsToUpdate(org.apache.hadoop.hbase.client.Connection conn, long latestPutTimestamp, org.apache.hadoop.hbase.TableName tableName) throws IOException, InterruptedException Waits for the replication checkpoint timestamp of each region server to meet or pass the timestamp of the latest Put operation on the backed-up table.- Parameters:
conn- Minicluster connectionlatestPutTimestamp- Timestamp of the latest Put operation on the backed-up table- Throws:
IOExceptionInterruptedException
-
getLatestPutTimestamp
Scans the backed-up table and returns the timestamp (ms) of the latest Put operation on the table.- Parameters:
table- The backed-up table to scan- Returns:
- Timestamp of the most recent Put on the backed-up table
- Throws:
IOException
-
restoreTableAndVerifyRowCount
private void restoreTableAndVerifyRowCount(org.apache.hadoop.hbase.client.Connection conn, org.apache.hadoop.hbase.backup.BackupAdmin client, org.apache.hadoop.hbase.TableName table, String backupId, long expectedRows) throws IOException Restores a table using the provided backup ID and ensure the table has the correct row count after- Throws:
IOException
-
getAllIncrementalBackupIds
Uses the list of all backup IDs to return a sublist of incremental backup IDs. This method assumes the first backup in the list is a full backup, followed by incremental backups. -
checkSucceeded
Returns status of backup- Throws:
IOException
-
getBackupInfo
- Throws:
IOException
-
createRestoreRequest
public org.apache.hadoop.hbase.backup.RestoreRequest createRestoreRequest(String backupRootDir, String backupId, boolean check, org.apache.hadoop.hbase.TableName[] fromTables, org.apache.hadoop.hbase.TableName[] toTables, boolean isOverwrite) Get restore request.- Parameters:
backupId- backup IDcheck- check the backupfromTables- table names to restore fromtoTables- new table names to restore toisOverwrite- overwrite the table(s)- Returns:
- an instance of RestoreRequest
-
verifyBackupExistenceAfterMerge
Iterates through the list of backups and verifies the full backup and latest incremental backup still exist, while also verifying all other backups no longer exist. This method is meant to be run after all incremental backups have been merged.- Throws:
IOException
-
removeNonexistentBackups
- Throws:
IOException
-
deleteMostRecentIncrementalBackup
private void deleteMostRecentIncrementalBackup(List<String> backupIds, org.apache.hadoop.hbase.backup.BackupAdmin client) throws IOException Performs the delete command for the most recently taken incremental backup, and also removes this backup from the list of backup IDs.- Throws:
IOException
-
verifyAllBackupsExist
Verifies all backups in the list of backup IDs actually exist on the filesystem.- Throws:
IOException
-
verifyNoBackupsExist
Verifies zero backups in the list of backup IDs exist on the filesystem.- Throws:
IOException
-
verifyBackupExists
- Throws:
IOException
-
verifyBackupDoesNotExist
- Throws:
IOException
-
setUpCluster
- Specified by:
setUpClusterin classIntegrationTestBase- Throws:
Exception
-
getTablename
Description copied from class:IntegrationTestBaseProvides the name of the table that is protected from random Chaos monkey activity- Specified by:
getTablenamein classIntegrationTestBase- Returns:
- table to not delete.
-
getColumnFamilies
Description copied from class:IntegrationTestBaseProvides the name of the CFs that are protected from random Chaos monkey activity (alter)- Specified by:
getColumnFamiliesin classIntegrationTestBase- Returns:
- set of cf names to protect.
-
initializeTestParameters
This method is useful for ensuring important test parameters are initialized when running integration tests in IntelliJ or in the command line with Maven. Tests executed in the command line via the bin/hbase command have their parameters set inIntegrationTestBase.processOptions(org.apache.hbase.thirdparty.org.apache.commons.cli.CommandLine) -
addOptions
- Overrides:
addOptionsin classIntegrationTestBase
-
processOptions
- Overrides:
processOptionsin classIntegrationTestBase
-