From c674c073eea03527d143bcabeeda44c291a261c8 Mon Sep 17 00:00:00 2001 From: Bryan Beaudreault Date: Wed, 13 Sep 2023 11:12:52 -0400 Subject: [PATCH] HBASE-28079 Unhandled TableExistsException and NamespaceExistException in BackupSystemTable (#5399) Signed-off-by: Duo Zhang --- .../hbase/backup/impl/BackupSystemTable.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupSystemTable.java b/hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupSystemTable.java index 04f43b5b0ea1..55f225f41cf1 100644 --- a/hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupSystemTable.java +++ b/hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupSystemTable.java @@ -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; @@ -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(); @@ -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); + } } }