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
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final byte[]
private static final byte[]
private static final byte[]
private static final byte[]
private static final String
(package private) static final byte[]
(package private) static final byte[]
private static final String
(package private) static final byte[]
private static final String
private static final byte[]
private TableName
Backup System table name for bulk loaded files.private final Connection
Connection to HBase cluster, shared among all instancesprivate static final byte[]
private static final byte[]
(package private) static final byte[]
private static final String
private static final org.slf4j.Logger
private 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 String
private static final String
(package private) static final byte[]
private static final String
private TableName
Backup system table (main) name(package private) static final byte[]
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addIncrementalBackupTableSet
(Set<TableName> tables, String backupRoot) Add tables to global incremental backup setvoid
addToBackupSet
(String name, String[] newTables) Add backup set (list of tables)private String
cellKeyToBackupSetName
(Cell current) Converts cell key to backup set name.private BackupInfo
cellToBackupInfo
(Cell current) Converts cell to backup info instance.private String[]
cellValueToBackupSet
(Cell current) Converts cell to backup set list.private void
void
close()
private byte[]
convertToByteArray
(String[] tables) private Delete
private Delete
createDeleteForBackupInfo
(String backupId) Creates Delete operation for a given backup idprivate Delete
private Delete
Creates Delete operation to delete backup set contentprivate Delete
createDeleteForIncrBackupTableSet
(String backupRoot) Creates Delete for incremental backup table setprivate Get
createGetForBackupInfo
(String backupId) Creates Get operation for a given backup idprivate Get
createGetForBackupSet
(String name) Creates Get operation to load backup set contentprivate Get
private Get
createGetForIncrBackupTableSet
(String backupRoot) Creates Get to retrieve incremental backup table set from backup system tableprivate Get
private Get
createGetForStartCode
(String rootPath) Creates Get operation to retrieve start code from backup system tableprivate Put
createPutForBackupInfo
(BackupInfo context) Creates Put operation for a given backup info objectprivate Put
createPutForBackupSet
(String name, String[] tables) Creates Put operation to update backup set content(package private) static Put
createPutForBulkLoadedFile
(TableName tn, byte[] fam, String p, String backupId, long ts, int idx) createPutForCommittedBulkload
(TableName table, byte[] region, Map<byte[], List<org.apache.hadoop.fs.Path>> finalPaths) private Put
createPutForDeleteOperation
(String[] backupIdList) private Put
createPutForIncrBackupTableSet
(Set<TableName> tables, String backupRoot) Creates Put to store incremental backup table setprivate Put
createPutForMergeOperation
(String[] backupIdList) createPutForPreparedBulkload
(TableName table, byte[] region, byte[] family, List<Pair<org.apache.hadoop.fs.Path, org.apache.hadoop.fs.Path>> pairs) private Put
createPutForRegionServerLastLogRollResult
(String server, Long timestamp, String backupRoot) Creates Put to store RS last log resultprivate Put
private Put
createPutForStartCode
(String startCode, String rootPath) Creates Put operation to store start code to backup system tableprivate Put
private Put
private Put
createPutForWriteRegionServerLogTimestamp
(TableName table, byte[] smap, String backupRoot) Creates Put to write RS last roll log timestamp mapprivate Scan
Creates Scan operation to load backup historyprivate Scan
Creates Scan operation to load backup set list(package private) static Scan
createScanForBulkLoadedFiles
(String backupId) (package private) static Scan
private Scan
createScanForReadLogTimestampMap
(String backupRoot) Creates Scan to load table-> { RS -> ts} map of mapsprivate Scan
createScanForReadRegionServerLastLogRollResult
(String backupRoot) Creates Scan operation to load last RS log roll resultsprivate void
createSystemTable
(Admin admin, TableDescriptor descriptor) void
deleteBackupInfo
(String backupId) Deletes backup status from backup system table tablevoid
deleteBackupSet
(String name) Delete backup setvoid
deleteBulkLoadedRows
(List<byte[]> rows) void
deleteIncrementalBackupTableSet
(String backupRoot) Deletes incremental backup set for a backup destinationstatic void
deleteSnapshot
(Connection conn) describeBackupSet
(String name) Get backup set description (list of tables)private String[]
private static void
ensureTableEnabled
(Admin admin, TableName tableName) void
void
void
fromTableServerTimestampProto
(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 String
private String
Get server's name from rowkeystatic String
getSnapshotName
(org.apache.hadoop.conf.Configuration conf) static TableDescriptor
getSystemTableDescriptor
(org.apache.hadoop.conf.Configuration conf) Get backup system table descriptorstatic TableDescriptor
getSystemTableForBulkLoadedDataDescriptor
(org.apache.hadoop.conf.Configuration conf) Get backup system table descriptorstatic TableName
getTableName
(org.apache.hadoop.conf.Configuration conf) static String
getTableNameAsString
(org.apache.hadoop.conf.Configuration conf) static TableName
getTableNameForBulkLoadedData
(org.apache.hadoop.conf.Configuration conf) private String
getTableNameForReadLogTimestampMap
(byte[] cloneRow) Get table name from rowkey(package private) static String
boolean
Checks if we have at least one backup session in backup system table This API is used by BackupLogCleanerboolean
Get backup set listprivate String[]
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) readBulkLoadedFiles
(String backupId, List<TableName> sTableList) readBulkloadRows
(List<TableName> tableList) 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.void
removeFromBackupSet
(String name, String[] toRemove) Remove tables from backup set (list of tables)static void
private BackupInfo
resultToBackupInfo
(Result res) Converts Result to BackupInfoprivate static byte[]
static void
snapshot
(Connection conn) private static boolean
snapshotExists
(Admin admin, String snapshotName) static boolean
snapshotExists
(Connection conn) void
Exclusive operations are: create, delete, mergevoid
startDeleteOperation
(String[] backupIdList) void
startMergeOperation
(String[] backupIdList) private org.apache.hadoop.hbase.shaded.protobuf.generated.BackupProtos.TableServerTimestamp
toTableServerTimestampProto
(TableName table, Map<String, Long> map) void
updateBackupInfo
(BackupInfo info) Updates status (state) of a backup session in backup system table tablevoid
updateProcessedTablesForMerge
(List<TableName> tables) private void
verifyNamespaceExists
(Admin admin) private void
waitForSystemTable
(Admin admin, TableName tableName) void
writeBackupStartCode
(Long startCode, String backupRoot) Write the start code (timestamp) to backup system table.void
writeBulkLoadedFiles
(List<TableName> sTableList, Map<byte[], List<org.apache.hadoop.fs.Path>>[] maps, String backupId) void
writeFilesForBulkLoadPreCommit
(TableName tabName, byte[] region, byte[] family, List<Pair<org.apache.hadoop.fs.Path, org.apache.hadoop.fs.Path>> pairs) void
writePathsPostBulkLoad
(TableName tabName, byte[] region, Map<byte[], List<org.apache.hadoop.fs.Path>> finalPaths) void
writeRegionServerLastLogRollResult
(String server, Long ts, String backupRoot) Writes Region Server last roll log result (timestamp) to backup system table tablevoid
writeRegionServerLogTimestamp
(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
-
STATE_COL
-
BL_PREPARE
-
BL_COMMIT
-
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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
updateBackupInfo
Updates status (state) of a backup session in backup system table table- Parameters:
info
- backup info- Throws:
IOException
- exception
-
readBulkLoadedFiles
- Throws:
IOException
-
readBulkLoadedFiles
public Map<byte[],List<org.apache.hadoop.fs.Path>>[] readBulkLoadedFiles(String backupId, List<TableName> sTableList) throws IOException - Throws:
IOException
-
deleteBackupInfo
Deletes backup status from backup system table table- Parameters:
backupId
- backup id- Throws:
IOException
- exception
-
writePathsPostBulkLoad
public void writePathsPostBulkLoad(TableName tabName, byte[] region, Map<byte[], List<org.apache.hadoop.fs.Path>> finalPaths) throws IOException- Throws:
IOException
-
writeFilesForBulkLoadPreCommit
public void writeFilesForBulkLoadPreCommit(TableName tabName, byte[] region, byte[] family, List<Pair<org.apache.hadoop.fs.Path, org.apache.hadoop.fs.Path>> pairs) throws IOException- Throws:
IOException
-
deleteBulkLoadedRows
- Throws:
IOException
-
readBulkloadRows
public Pair<Map<TableName,Map<String, readBulkloadRowsMap<String, List<Pair<String, Boolean>>>>>, List<byte[]>> (List<TableName> tableList) throws IOException - Throws:
IOException
-
writeBulkLoadedFiles
public void writeBulkLoadedFiles(List<TableName> sTableList, Map<byte[], List<org.apache.hadoop.fs.Path>>[] maps, String backupId) throws IOException- 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
-
getTablesForBackupType
- 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 theBackupInfo
backupRoot
- backup destination path to retrieve backup history for- Returns:
- a map containing (a subset of) the provided
TableName
s, 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
-
createPutForCommittedBulkload
-
snapshot
- Throws:
IOException
-
restoreFromSnapshot
- Throws:
IOException
-
snapshotExists
- Throws:
IOException
-
snapshotExists
- Throws:
IOException
-
deleteSnapshot
- Throws:
IOException
-
createPutForPreparedBulkload
-
createDeleteForOrigBulkLoad
-
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
-
getTableNameFromOrigBulkLoadRow
-
getRegionNameFromOrigBulkLoadRow
-
createScanForBulkLoadedFiles
-
createPutForBulkLoadedFile
static Put createPutForBulkLoadedFile(TableName tn, byte[] fam, String p, String backupId, long ts, int idx) -
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
-