Search in sources :

Example 1 with BackupType

use of org.apache.hadoop.hbase.backup.BackupType in project hbase by apache.

the class BackupAdminImpl method getAffectedBackupInfos.

private List<BackupInfo> getAffectedBackupInfos(BackupInfo backupInfo, TableName tn, BackupSystemTable table) throws IOException {
    LOG.debug("GetAffectedBackupInfos for: " + backupInfo.getBackupId() + " table=" + tn);
    long ts = backupInfo.getStartTs();
    List<BackupInfo> list = new ArrayList<BackupInfo>();
    List<BackupInfo> history = table.getBackupHistory(backupInfo.getBackupRootDir());
    // break when backupInfo reached
    for (BackupInfo info : history) {
        if (info.getStartTs() == ts) {
            break;
        }
        List<TableName> tables = info.getTableNames();
        if (tables.contains(tn)) {
            BackupType bt = info.getType();
            if (bt == BackupType.FULL) {
                // Clear list if we encounter FULL backup
                list.clear();
            } else {
                LOG.debug("GetAffectedBackupInfos for: " + backupInfo.getBackupId() + " table=" + tn + " added " + info.getBackupId() + " tables=" + info.getTableListAsString());
                list.add(info);
            }
        }
    }
    return list;
}
Also used : BackupInfo(org.apache.hadoop.hbase.backup.BackupInfo) TableName(org.apache.hadoop.hbase.TableName) ArrayList(java.util.ArrayList) BackupType(org.apache.hadoop.hbase.backup.BackupType)

Example 2 with BackupType

use of org.apache.hadoop.hbase.backup.BackupType in project hbase by apache.

the class BackupAdminImpl method backupTables.

@Override
public String backupTables(BackupRequest request) throws IOException {
    BackupType type = request.getBackupType();
    String targetRootDir = request.getTargetRootDir();
    List<TableName> tableList = request.getTableList();
    String backupId = BackupRestoreConstants.BACKUPID_PREFIX + EnvironmentEdgeManager.currentTime();
    if (type == BackupType.INCREMENTAL) {
        Set<TableName> incrTableSet = null;
        try (BackupSystemTable table = new BackupSystemTable(conn)) {
            incrTableSet = table.getIncrementalBackupTableSet(targetRootDir);
        }
        if (incrTableSet.isEmpty()) {
            String msg = "Incremental backup table set contains no tables. " + "You need to run full backup first " + (tableList != null ? "on " + StringUtils.join(tableList, ",") : "");
            throw new IOException(msg);
        }
        if (tableList != null) {
            tableList.removeAll(incrTableSet);
            if (!tableList.isEmpty()) {
                String extraTables = StringUtils.join(tableList, ",");
                String msg = "Some tables (" + extraTables + ") haven't gone through full backup. " + "Perform full backup on " + extraTables + " first, " + "then retry the command";
                throw new IOException(msg);
            }
        }
        tableList = Lists.newArrayList(incrTableSet);
    }
    if (tableList != null && !tableList.isEmpty()) {
        for (TableName table : tableList) {
            String targetTableBackupDir = HBackupFileSystem.getTableBackupDir(targetRootDir, backupId, table);
            Path targetTableBackupDirPath = new Path(targetTableBackupDir);
            FileSystem outputFs = FileSystem.get(targetTableBackupDirPath.toUri(), conn.getConfiguration());
            if (outputFs.exists(targetTableBackupDirPath)) {
                throw new IOException("Target backup directory " + targetTableBackupDir + " exists already.");
            }
        }
        ArrayList<TableName> nonExistingTableList = null;
        try (Admin admin = conn.getAdmin()) {
            for (TableName tableName : tableList) {
                if (!admin.tableExists(tableName)) {
                    if (nonExistingTableList == null) {
                        nonExistingTableList = new ArrayList<>();
                    }
                    nonExistingTableList.add(tableName);
                }
            }
        }
        if (nonExistingTableList != null) {
            if (type == BackupType.INCREMENTAL) {
                // Update incremental backup set
                tableList = excludeNonExistingTables(tableList, nonExistingTableList);
            } else {
                // Throw exception only in full mode - we try to backup non-existing table
                throw new IOException("Non-existing tables found in the table list: " + nonExistingTableList);
            }
        }
    }
    // update table list
    BackupRequest.Builder builder = new BackupRequest.Builder();
    request = builder.withBackupType(request.getBackupType()).withTableList(tableList).withTargetRootDir(request.getTargetRootDir()).withBackupSetName(request.getBackupSetName()).withTotalTasks(request.getTotalTasks()).withBandwidthPerTasks((int) request.getBandwidth()).build();
    if (type == BackupType.FULL) {
        new FullTableBackupClient(conn, backupId, request).execute();
    } else {
        new IncrementalTableBackupClient(conn, backupId, request).execute();
    }
    return backupId;
}
Also used : Path(org.apache.hadoop.fs.Path) BackupRequest(org.apache.hadoop.hbase.backup.BackupRequest) IOException(java.io.IOException) BackupAdmin(org.apache.hadoop.hbase.backup.BackupAdmin) Admin(org.apache.hadoop.hbase.client.Admin) TableName(org.apache.hadoop.hbase.TableName) FileSystem(org.apache.hadoop.fs.FileSystem) HBackupFileSystem(org.apache.hadoop.hbase.backup.HBackupFileSystem) BackupType(org.apache.hadoop.hbase.backup.BackupType)

Aggregations

TableName (org.apache.hadoop.hbase.TableName)2 BackupType (org.apache.hadoop.hbase.backup.BackupType)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 BackupAdmin (org.apache.hadoop.hbase.backup.BackupAdmin)1 BackupInfo (org.apache.hadoop.hbase.backup.BackupInfo)1 BackupRequest (org.apache.hadoop.hbase.backup.BackupRequest)1 HBackupFileSystem (org.apache.hadoop.hbase.backup.HBackupFileSystem)1 Admin (org.apache.hadoop.hbase.client.Admin)1