HBASE-17542 Move backup system table into separate namespace

This commit is contained in:
tedyu 2017-04-20 02:57:24 -07:00
parent 0953c14470
commit b1ef8dd43a
3 changed files with 24 additions and 5 deletions

View File

@ -54,9 +54,9 @@ public class BackupHFileCleaner extends BaseHFileCleanerDelegate implements Abor
private boolean aborted;
private Configuration conf;
private Connection connection;
private long prevReadFromBackupTbl = 0, // timestamp of most recent read from hbase:backup table
secondPrevReadFromBackupTbl = 0; // timestamp of 2nd most recent read from hbase:backup table
//used by unit test to skip reading hbase:backup
private long prevReadFromBackupTbl = 0, // timestamp of most recent read from backup:system table
secondPrevReadFromBackupTbl = 0; // timestamp of 2nd most recent read from backup:system table
//used by unit test to skip reading backup:system
private boolean checkForFullyBackedUpTables = true;
private List<TableName> fullyBackedUpTables = null;
@ -117,7 +117,7 @@ public class BackupHFileCleaner extends BaseHFileCleanerDelegate implements Abor
Iterable<FileStatus> deletables = Iterables.filter(files, new Predicate<FileStatus>() {
@Override
public boolean apply(FileStatus file) {
// If the file is recent, be conservative and wait for one more scan of hbase:backup table
// If the file is recent, be conservative and wait for one more scan of backup:system table
if (file.getModificationTime() > secondPrevReadFromBackupTbl) {
return false;
}

View File

@ -30,7 +30,7 @@ public interface BackupRestoreConstants {
* Backup/Restore constants
*/
public final static String BACKUP_SYSTEM_TABLE_NAME_KEY = "hbase.backup.system.table.name";
public final static String BACKUP_SYSTEM_TABLE_NAME_DEFAULT = "hbase:backup";
public final static String BACKUP_SYSTEM_TABLE_NAME_DEFAULT = "backup:system";
public final static String BACKUP_SYSTEM_TTL_KEY = "hbase.backup.system.ttl";

View File

@ -42,6 +42,7 @@ import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.NamespaceDescriptor;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.backup.BackupInfo;
@ -165,6 +166,8 @@ public final class BackupSystemTable implements Closeable {
private void checkSystemTable() throws IOException {
try (Admin admin = connection.getAdmin();) {
verifyNamespaceExists(admin);
if (!admin.tableExists(tableName)) {
HTableDescriptor backupHTD =
BackupSystemTable.getSystemTableDescriptor(connection.getConfiguration());
@ -174,6 +177,22 @@ public final class BackupSystemTable implements Closeable {
}
}
private void verifyNamespaceExists(Admin admin) throws IOException {
String namespaceName = tableName.getNamespaceAsString();
NamespaceDescriptor ns = NamespaceDescriptor.create(namespaceName).build();
NamespaceDescriptor[] list = admin.listNamespaceDescriptors();
boolean exists = false;
for( NamespaceDescriptor nsd: list) {
if (nsd.getName().equals(ns.getName())) {
exists = true;
break;
}
}
if (!exists) {
admin.createNamespace(ns);
}
}
private void waitForSystemTable(Admin admin) throws IOException {
long TIMEOUT = 60000;
long startTime = EnvironmentEdgeManager.currentTime();