Skip to content

Commit

Permalink
HBASE-28079 Unhandled TableExistsException and NamespaceExistExceptio…
Browse files Browse the repository at this point in the history
…n in BackupSystemTable (#5399)

Signed-off-by: Duo Zhang <[email protected]>
  • Loading branch information
bbeaudreault committed Sep 13, 2023
1 parent 9a1de14 commit 3b34bc2
Showing 1 changed file with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.NamespaceDescriptor;
import org.apache.hadoop.hbase.NamespaceExistException;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableExistsException;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.backup.BackupInfo;
import org.apache.hadoop.hbase.backup.BackupInfo.BackupState;
Expand Down Expand Up @@ -202,17 +204,28 @@ private void checkSystemTable() throws IOException {
Configuration conf = connection.getConfiguration();
if (!admin.tableExists(tableName)) {
TableDescriptor backupHTD = BackupSystemTable.getSystemTableDescriptor(conf);
admin.createTable(backupHTD);
createSystemTable(admin, backupHTD);
}
if (!admin.tableExists(bulkLoadTableName)) {
TableDescriptor blHTD = BackupSystemTable.getSystemTableForBulkLoadedDataDescriptor(conf);
admin.createTable(blHTD);
createSystemTable(admin, blHTD);
}
waitForSystemTable(admin, tableName);
waitForSystemTable(admin, bulkLoadTableName);
}
}

private void createSystemTable(Admin admin, TableDescriptor descriptor) throws IOException {
try {
admin.createTable(descriptor);
} catch (TableExistsException e) {
// swallow because this class is initialized in concurrent environments (i.e. bulkloads),
// so may be subject to race conditions where one caller succeeds in creating the
// table and others fail because it now exists
LOG.debug("Table {} already exists, ignoring", descriptor.getTableName(), e);
}
}

private void verifyNamespaceExists(Admin admin) throws IOException {
String namespaceName = tableName.getNamespaceAsString();
NamespaceDescriptor ns = NamespaceDescriptor.create(namespaceName).build();
Expand All @@ -225,7 +238,14 @@ private void verifyNamespaceExists(Admin admin) throws IOException {
}
}
if (!exists) {
admin.createNamespace(ns);
try {
admin.createNamespace(ns);
} catch (NamespaceExistException e) {
// swallow because this class is initialized in concurrent environments (i.e. bulkloads),
// so may be subject to race conditions where one caller succeeds in creating the
// namespace and others fail because it now exists
LOG.debug("Namespace {} already exists, ignoring", ns.getName(), e);
}
}
}

Expand Down

0 comments on commit 3b34bc2

Please sign in to comment.