Class BackupSystemTable
java.lang.Object
org.apache.hadoop.hbase.backup.impl.BackupSystemTable
- All Implemented Interfaces:
Closeable,AutoCloseable
This class provides API to access backup system table
Backup system table schema:
Backup system table schema:
- 1. Backup sessions rowkey= "session:"+backupId; value =serialized BackupInfo
- 2. Backup start code rowkey = "startcode:"+backupRoot; value = startcode
- 3. Incremental backup set rowkey="incrbackupset:"+backupRoot; table="meta:"+tablename of include table; value=empty
- 4. Table-RS-timestamp map rowkey="trslm:"+backupRoot+table_name; value = map[RS-> last WAL timestamp]
- 5. RS - WAL ts map rowkey="rslogts:"+backupRoot +server; value = last WAL timestamp
- 6. WALs recorded rowkey="wals:"+WAL unique file name; value = backupId and full WAL file name
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final byte[]private static final byte[]private static final byte[]private static final byte[]private static final Stringprivate static final String(package private) static final byte[]private static final Stringprivate static final byte[]private TableNameBackup System table name for bulk loaded files.private final ConnectionConnection to HBase cluster, shared among all instancesprivate static final byte[]private static final byte[](package private) static final byte[]private static final Stringprivate static final org.slf4j.Loggerprivate static final byte[](package private) static final byte[]Stores other metaprivate static final String(package private) static final byte[]private static final String(package private) static final byte[]Stores backup sessions (contexts)private static final Stringprivate static final Stringprivate static final Stringprivate TableNameBackup system table (main) name(package private) static final byte[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddIncrementalBackupTableSet(Set<TableName> tables, String backupRoot) Add tables to global incremental backup setvoidaddToBackupSet(String name, String[] newTables) Add backup set (list of tables)private StringcellKeyToBackupSetName(Cell current) Converts cell key to backup set name.private BackupInfocellToBackupInfo(Cell current) Converts cell to backup info instance.private String[]cellValueToBackupSet(Cell current) Converts cell to backup set list.private voidvoidclose()private byte[]convertToByteArray(String[] tables) private Deleteprivate DeletecreateDeleteForBackupInfo(String backupId) Creates Delete operation for a given backup idprivate Deleteprivate DeleteCreates Delete operation to delete backup set contentprivate DeletecreateDeleteForIncrBackupTableSet(String backupRoot) Creates Delete for incremental backup table setprivate GetcreateGetForBackupInfo(String backupId) Creates Get operation for a given backup idprivate GetcreateGetForBackupSet(String name) Creates Get operation to load backup set contentprivate Getprivate GetcreateGetForIncrBackupTableSet(String backupRoot) Creates Get to retrieve incremental backup table set from backup system tableprivate Getprivate GetcreateGetForStartCode(String rootPath) Creates Get operation to retrieve start code from backup system tableprivate PutcreatePutForBackupInfo(BackupInfo context) Creates Put operation for a given backup info objectprivate PutcreatePutForBackupSet(String name, String[] tables) Creates Put operation to update backup set contentcreatePutForBulkLoad(TableName table, byte[] region, Map<byte[], List<org.apache.hadoop.fs.Path>> columnFamilyToHFilePaths) Creates Put's for bulk loads.private PutcreatePutForDeleteOperation(String[] backupIdList) private PutcreatePutForIncrBackupTableSet(Set<TableName> tables, String backupRoot) Creates Put to store incremental backup table setprivate PutcreatePutForMergeOperation(String[] backupIdList) private PutcreatePutForRegionServerLastLogRollResult(String server, Long timestamp, String backupRoot) Creates Put to store RS last log resultprivate Putprivate PutcreatePutForStartCode(String startCode, String rootPath) Creates Put operation to store start code to backup system tableprivate Putprivate Putprivate PutcreatePutForWriteRegionServerLogTimestamp(TableName table, byte[] smap, String backupRoot) Creates Put to write RS last roll log timestamp mapprivate ScanCreates Scan operation to load backup historyprivate ScanCreates Scan operation to load backup set list(package private) static ScancreateScanForBulkLoadedFiles(String backupId) (package private) static ScanCreates a scan to read all registered bulk loads for the given table, or for all tables iftableisnull.private ScancreateScanForReadLogTimestampMap(String backupRoot) Creates Scan to load table-> { RS -> ts} map of mapsprivate ScancreateScanForReadRegionServerLastLogRollResult(String backupRoot) Creates Scan operation to load last RS log roll resultsprivate voidcreateSystemTable(Admin admin, TableDescriptor descriptor) voiddeleteBackupInfo(String backupId) Deletes backup status from backup system table tablevoiddeleteBackupSet(String name) Delete backup setvoiddeleteBulkLoadedRows(List<byte[]> rows) Removes entries from the table that tracks all bulk loaded hfiles.voiddeleteIncrementalBackupTableSet(String backupRoot) Deletes incremental backup set for a backup destinationstatic voiddeleteSnapshot(Connection conn) describeBackupSet(String name) Get backup set description (list of tables)private String[]private static voidensureTableEnabled(Admin admin, TableName tableName) voidvoidvoidfromTableServerTimestampProto(org.apache.hadoop.hbase.shaded.protobuf.generated.BackupProtos.TableServerTimestamp proto) Get all backups historygetBackupHistory(boolean onlyCompleted) Get all completed backup information (in desc order by time)getBackupHistory(int n, BackupInfo.Filter... filters) Get backup history records filtered by list of filters.getBackupHistory(String backupRoot) Get history for backup destinationGet history for a tablegetBackupHistoryForTableSet(Set<TableName> set, String backupRoot) Goes through all backup history corresponding to the provided root folder, and collects all backup info mentioning each of the provided tables.Get all backup sessions with a given state (in descending order by time)getHistory(int n) Get first n backup history recordsgetIncrementalBackupTableSet(String backupRoot) Return the current tables covered by incremental backup.String[]String[](package private) static Stringprivate StringGet server's name from rowkeystatic StringgetSnapshotName(org.apache.hadoop.conf.Configuration conf) static TableDescriptorgetSystemTableDescriptor(org.apache.hadoop.conf.Configuration conf) Get backup system table descriptorstatic TableDescriptorgetSystemTableForBulkLoadedDataDescriptor(org.apache.hadoop.conf.Configuration conf) Get backup system table descriptorstatic TableNamegetTableName(org.apache.hadoop.conf.Configuration conf) static StringgetTableNameAsString(org.apache.hadoop.conf.Configuration conf) static TableNamegetTableNameForBulkLoadedData(org.apache.hadoop.conf.Configuration conf) private StringgetTableNameForReadLogTimestampMap(byte[] cloneRow) Get table name from rowkey(package private) static StringRetrieve all table names that are part of any known backupbooleanChecks if we have at least one backup session in backup system table This API is used by BackupLogCleanerbooleanGet backup set listprivate String[]processBulkLoadRowScan(Scan scan) readBackupInfo(String backupId) Reads backup status object (instance of backup info) from backup system table tablereadBackupStartCode(String backupRoot) Read the last backup start code (timestamp) of last successful backup.readBulkLoadedFiles(String backupId) Reads all registered bulk loads.readBulkloadRows(Collection<TableName> tableList) Reads the registered bulk loads for the given tables.readLogTimestampMap(String backupRoot) Read the timestamp for each region server log after the last successful backup.readRegionServerLastLogRollResult(String backupRoot) Get the Region Servers log information after the last log roll from backup system table.voidregisterBulkLoad(TableName tableName, byte[] region, Map<byte[], List<org.apache.hadoop.fs.Path>> cfToHfilePath) Registers a bulk load.voidremoveFromBackupSet(String name, String[] toRemove) Remove tables from backup set (list of tables)static voidprivate BackupInforesultToBackupInfo(Result res) Converts Result to BackupInfoprivate static byte[]static voidsnapshot(Connection conn) private static booleansnapshotExists(Admin admin, String snapshotName) static booleansnapshotExists(Connection conn) voidExclusive operations are: create, delete, mergevoidstartDeleteOperation(String[] backupIdList) voidstartMergeOperation(String[] backupIdList) private org.apache.hadoop.hbase.shaded.protobuf.generated.BackupProtos.TableServerTimestamptoTableServerTimestampProto(TableName table, Map<String, Long> map) voidupdateBackupInfo(BackupInfo info) Updates status (state) of a backup session in backup system table tablevoidupdateProcessedTablesForMerge(List<TableName> tables) private voidverifyNamespaceExists(Admin admin) private voidwaitForSystemTable(Admin admin, TableName tableName) voidwriteBackupStartCode(Long startCode, String backupRoot) Write the start code (timestamp) to backup system table.voidwriteRegionServerLastLogRollResult(String server, Long ts, String backupRoot) Writes Region Server last roll log result (timestamp) to backup system table tablevoidwriteRegionServerLogTimestamp(Set<TableName> tables, Map<String, Long> newTimestamps, String backupRoot) Write the current timestamps for each regionserver to backup system table after a successful full or incremental backup.
-
Field Details
-
LOG
-
tableName
Backup system table (main) name -
bulkLoadTableName
Backup System table name for bulk loaded files. We keep all bulk loaded file references in a separate table because we have to isolate general backup operations: create, merge etc from activity of RegionObserver, which controls process of a bulk loadingBackupObserver -
SESSIONS_FAMILY
Stores backup sessions (contexts) -
META_FAMILY
Stores other meta -
BULK_LOAD_FAMILY
-
connection
Connection to HBase cluster, shared among all instances -
BACKUP_INFO_PREFIX
- See Also:
-
START_CODE_ROW
- See Also:
-
ACTIVE_SESSION_ROW
-
ACTIVE_SESSION_COL
-
ACTIVE_SESSION_YES
-
ACTIVE_SESSION_NO
-
INCR_BACKUP_SET
- See Also:
-
TABLE_RS_LOG_MAP_PREFIX
- See Also:
-
RS_LOG_TS_PREFIX
- See Also:
-
BULK_LOAD_PREFIX
- See Also:
-
BULK_LOAD_PREFIX_BYTES
-
DELETE_OP_ROW
-
MERGE_OP_ROW
-
TBL_COL
-
FAM_COL
-
PATH_COL
-
SET_KEY_PREFIX
- See Also:
-
BLK_LD_DELIM
- See Also:
-
EMPTY_VALUE
-
NULL
- See Also:
-
-
Constructor Details
-
BackupSystemTable
- Throws:
IOException
-
-
Method Details
-
checkSystemTable
- Throws:
IOException
-
createSystemTable
- Throws:
IOException
-
verifyNamespaceExists
- Throws:
IOException
-
waitForSystemTable
- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
updateBackupInfo
Updates status (state) of a backup session in backup system table table- Parameters:
info- backup info- Throws:
IOException- exception
-
readBulkLoadedFiles
- Throws:
IOException
-
deleteBackupInfo
Deletes backup status from backup system table table- Parameters:
backupId- backup id- Throws:
IOException- exception
-
registerBulkLoad
public void registerBulkLoad(TableName tableName, byte[] region, Map<byte[], List<org.apache.hadoop.fs.Path>> cfToHfilePath) throws IOExceptionRegisters a bulk load.- Parameters:
tableName- table nameregion- the region receiving hfilecfToHfilePath- column family and associated hfiles- Throws:
IOException
-
deleteBulkLoadedRows
Removes entries from the table that tracks all bulk loaded hfiles.- Parameters:
rows- the row keys of the entries to be deleted- Throws:
IOException
-
readBulkloadRows
Reads all registered bulk loads.- Throws:
IOException
-
readBulkloadRows
Reads the registered bulk loads for the given tables.- Throws:
IOException
-
processBulkLoadRowScan
- Throws:
IOException
-
readBackupInfo
Reads backup status object (instance of backup info) from backup system table table- Parameters:
backupId- backup id- Returns:
- Current status of backup session or null
- Throws:
IOException
-
readBackupStartCode
Read the last backup start code (timestamp) of last successful backup. Will return null if there is no start code stored on hbase or the value is of length 0. These two cases indicate there is no successful backup completed so far.- Parameters:
backupRoot- directory path to backup destination- Returns:
- the timestamp of last successful backup
- Throws:
IOException- exception
-
writeBackupStartCode
Write the start code (timestamp) to backup system table. If passed in null, then write 0 byte.- Parameters:
startCode- start codebackupRoot- root directory path to backup- Throws:
IOException- exception
-
startBackupExclusiveOperation
Exclusive operations are: create, delete, merge- Throws:
IOException- if a table operation fails or an active backup exclusive operation is already underway
-
createPutForStartBackupSession
-
finishBackupExclusiveOperation
- Throws:
IOException
-
createPutForStopBackupSession
-
readRegionServerLastLogRollResult
Get the Region Servers log information after the last log roll from backup system table.- Parameters:
backupRoot- root directory path to backup- Returns:
- RS log info
- Throws:
IOException- exception
-
writeRegionServerLastLogRollResult
public void writeRegionServerLastLogRollResult(String server, Long ts, String backupRoot) throws IOException Writes Region Server last roll log result (timestamp) to backup system table table- Parameters:
server- Region Server namets- last log timestampbackupRoot- root directory path to backup- Throws:
IOException- exception
-
getBackupHistory
Get all completed backup information (in desc order by time)- Parameters:
onlyCompleted- true, if only successfully completed sessions- Returns:
- history info of BackupCompleteData
- Throws:
IOException- exception
-
getBackupHistory
Get all backups history- Returns:
- list of backup info
- Throws:
IOException- if getting the backup history fails
-
getHistory
Get first n backup history records- Parameters:
n- number of records, if n== -1 - max number is ignored- Returns:
- list of records
- Throws:
IOException- if getting the backup history fails
-
getBackupHistory
Get backup history records filtered by list of filters.- Parameters:
n- max number of records, if n == -1 , then max number is ignoredfilters- list of filters- Returns:
- backup records
- Throws:
IOException- if getting the backup history fails
-
getTablesIncludedInBackups
Retrieve all table names that are part of any known backup- Throws:
IOException
-
getBackupHistory
Get history for backup destination- Parameters:
backupRoot- backup destination path- Returns:
- List of backup info
- Throws:
IOException- if getting the backup history fails
-
getBackupHistoryForTable
Get history for a table- Parameters:
name- table name- Returns:
- history for a table
- Throws:
IOException- if getting the backup history fails
-
getBackupHistoryForTableSet
public Map<TableName,List<BackupInfo>> getBackupHistoryForTableSet(Set<TableName> set, String backupRoot) throws IOException Goes through all backup history corresponding to the provided root folder, and collects all backup info mentioning each of the provided tables.- Parameters:
set- the tables for which to collect theBackupInfobackupRoot- backup destination path to retrieve backup history for- Returns:
- a map containing (a subset of) the provided
TableNames, mapped to a list of at least oneBackupInfo - Throws:
IOException- if getting the backup history fails
-
getBackupInfos
Get all backup sessions with a given state (in descending order by time)- Parameters:
state- backup session state- Returns:
- history info of backup info objects
- Throws:
IOException- exception
-
writeRegionServerLogTimestamp
public void writeRegionServerLogTimestamp(Set<TableName> tables, Map<String, Long> newTimestamps, String backupRoot) throws IOExceptionWrite the current timestamps for each regionserver to backup system table after a successful full or incremental backup. The saved timestamp is of the last log file that was backed up already.- Parameters:
tables- tablesnewTimestamps- timestampsbackupRoot- root directory path to backup- Throws:
IOException- exception
-
readLogTimestampMap
Read the timestamp for each region server log after the last successful backup. Each table has its own set of the timestamps. The info is stored for each table as a concatenated string of rs->timestapmp- Parameters:
backupRoot- root directory path to backup- Returns:
- the timestamp for each region server. key: tableName value: RegionServer,PreviousTimeStamp
- Throws:
IOException- exception
-
toTableServerTimestampProto
private org.apache.hadoop.hbase.shaded.protobuf.generated.BackupProtos.TableServerTimestamp toTableServerTimestampProto(TableName table, Map<String, Long> map) -
fromTableServerTimestampProto
private HashMap<String,Long> fromTableServerTimestampProto(org.apache.hadoop.hbase.shaded.protobuf.generated.BackupProtos.TableServerTimestamp proto) -
getIncrementalBackupTableSet
Return the current tables covered by incremental backup.- Parameters:
backupRoot- root directory path to backup- Returns:
- set of tableNames
- Throws:
IOException- exception
-
addIncrementalBackupTableSet
public void addIncrementalBackupTableSet(Set<TableName> tables, String backupRoot) throws IOException Add tables to global incremental backup set- Parameters:
tables- set of tablesbackupRoot- root directory path to backup- Throws:
IOException- exception
-
deleteIncrementalBackupTableSet
Deletes incremental backup set for a backup destination- Parameters:
backupRoot- backup root- Throws:
IOException
-
hasBackupSessions
Checks if we have at least one backup session in backup system table This API is used by BackupLogCleaner- Returns:
- true, if - at least one session exists in backup system table table
- Throws:
IOException- exception
-
listBackupSets
Get backup set list- Returns:
- backup set list
- Throws:
IOException- if a table or scanner operation fails
-
describeBackupSet
Get backup set description (list of tables)- Parameters:
name- set's name- Returns:
- list of tables in a backup set
- Throws:
IOException- if a table operation fails
-
addToBackupSet
Add backup set (list of tables)- Parameters:
name- set namenewTables- list of tables, comma-separated- Throws:
IOException- if a table operation fails
-
removeFromBackupSet
Remove tables from backup set (list of tables)- Parameters:
name- set nametoRemove- list of tables- Throws:
IOException- if a table operation or deleting the backup set fails
-
merge
-
disjoin
-
deleteBackupSet
Delete backup set- Parameters:
name- set's name- Throws:
IOException- if getting or deleting the table fails
-
getSystemTableDescriptor
Get backup system table descriptor- Returns:
- table's descriptor
-
getTableName
-
getTableNameAsString
-
getSnapshotName
-
getSystemTableForBulkLoadedDataDescriptor
public static TableDescriptor getSystemTableForBulkLoadedDataDescriptor(org.apache.hadoop.conf.Configuration conf) Get backup system table descriptor- Returns:
- table's descriptor
-
getTableNameForBulkLoadedData
-
createPutForBackupInfo
Creates Put operation for a given backup info object- Parameters:
context- backup info- Returns:
- put operation
- Throws:
IOException- exception
-
createGetForBackupInfo
Creates Get operation for a given backup id- Parameters:
backupId- backup's ID- Returns:
- get operation
- Throws:
IOException- exception
-
createDeleteForBackupInfo
Creates Delete operation for a given backup id- Parameters:
backupId- backup's ID- Returns:
- delete operation
-
resultToBackupInfo
Converts Result to BackupInfo- Parameters:
res- HBase result- Returns:
- backup info instance
- Throws:
IOException- exception
-
createGetForStartCode
Creates Get operation to retrieve start code from backup system table- Returns:
- get operation
- Throws:
IOException- exception
-
createPutForStartCode
Creates Put operation to store start code to backup system table- Returns:
- put operation
-
createGetForIncrBackupTableSet
Creates Get to retrieve incremental backup table set from backup system table- Returns:
- get operation
- Throws:
IOException- exception
-
createPutForIncrBackupTableSet
Creates Put to store incremental backup table set- Parameters:
tables- tables- Returns:
- put operation
-
createDeleteForIncrBackupTableSet
Creates Delete for incremental backup table set- Parameters:
backupRoot- backup root- Returns:
- delete operation
-
createScanForBackupHistory
Creates Scan operation to load backup history- Returns:
- scan operation
-
cellToBackupInfo
Converts cell to backup info instance.- Parameters:
current- current cell- Returns:
- backup backup info instance
- Throws:
IOException- exception
-
createPutForWriteRegionServerLogTimestamp
private Put createPutForWriteRegionServerLogTimestamp(TableName table, byte[] smap, String backupRoot) Creates Put to write RS last roll log timestamp map- Parameters:
table- tablesmap- map, containing RS:ts- Returns:
- put operation
-
createScanForReadLogTimestampMap
Creates Scan to load table-> { RS -> ts} map of maps- Returns:
- scan operation
-
getTableNameForReadLogTimestampMap
Get table name from rowkey- Parameters:
cloneRow- rowkey- Returns:
- table name
-
createPutForRegionServerLastLogRollResult
private Put createPutForRegionServerLastLogRollResult(String server, Long timestamp, String backupRoot) Creates Put to store RS last log result- Parameters:
server- server nametimestamp- log roll result (timestamp)- Returns:
- put operation
-
createScanForReadRegionServerLastLogRollResult
Creates Scan operation to load last RS log roll results- Returns:
- scan operation
-
getServerNameForReadRegionServerLastLogRollResult
Get server's name from rowkey- Parameters:
row- rowkey- Returns:
- server's name
-
createPutForBulkLoad
private static List<Put> createPutForBulkLoad(TableName table, byte[] region, Map<byte[], List<org.apache.hadoop.fs.Path>> columnFamilyToHFilePaths) Creates Put's for bulk loads. -
snapshot
- Throws:
IOException
-
restoreFromSnapshot
- Throws:
IOException
-
snapshotExists
- Throws:
IOException
-
snapshotExists
- Throws:
IOException
-
deleteSnapshot
- Throws:
IOException
-
createPutForDeleteOperation
-
createDeleteForBackupDeleteOperation
-
createGetForDeleteOperation
-
startDeleteOperation
- Throws:
IOException
-
finishDeleteOperation
- Throws:
IOException
-
getListOfBackupIdsFromDeleteOperation
- Throws:
IOException
-
createPutForMergeOperation
-
isMergeInProgress
- Throws:
IOException
-
createPutForUpdateTablesForMerge
-
createDeleteForBackupMergeOperation
-
createGetForMergeOperation
-
startMergeOperation
- Throws:
IOException
-
updateProcessedTablesForMerge
- Throws:
IOException
-
finishMergeOperation
- Throws:
IOException
-
getListOfBackupIdsFromMergeOperation
- Throws:
IOException
-
createScanForOrigBulkLoadedFiles
Creates a scan to read all registered bulk loads for the given table, or for all tables iftableisnull. -
getTableNameFromOrigBulkLoadRow
-
getRegionNameFromOrigBulkLoadRow
-
createScanForBulkLoadedFiles
-
createScanForBackupSetList
Creates Scan operation to load backup set list- Returns:
- scan operation
-
createGetForBackupSet
Creates Get operation to load backup set content- Returns:
- get operation
-
createDeleteForBackupSet
Creates Delete operation to delete backup set content- Parameters:
name- backup set's name- Returns:
- delete operation
-
createPutForBackupSet
Creates Put operation to update backup set content- Parameters:
name- backup set's nametables- list of tables- Returns:
- put operation
-
convertToByteArray
-
cellValueToBackupSet
Converts cell to backup set list.- Parameters:
current- current cell- Returns:
- backup set as array of table names
-
cellKeyToBackupSetName
Converts cell key to backup set name.- Parameters:
current- current cell- Returns:
- backup set name
-
rowkey
-
ensureTableEnabled
- Throws:
IOException
-