From fc5839fd5c7538839ba85171e3df3e13bbbdfa61 Mon Sep 17 00:00:00 2001 From: Bryan Beaudreault Date: Tue, 12 Sep 2023 15:47:46 -0400 Subject: [PATCH 1/2] HBASE-28079 Unhandled TableExistsException and NamespaceExistException in BackupSystemTable --- .../hbase/backup/impl/BackupSystemTable.java | 20 ++++++++++++++++--- 1 file changed, 17 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..aaba41f20891 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,25 @@ 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) { + 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 +235,11 @@ private void verifyNamespaceExists(Admin admin) throws IOException { } } if (!exists) { - admin.createNamespace(ns); + try { + admin.createNamespace(ns); + } catch (NamespaceExistException e) { + LOG.debug("Namespace {} already exists, ignoring", ns.getName(), e); + } } } From a6446a7f89135591e431dea6b6133d29480b3777 Mon Sep 17 00:00:00 2001 From: Bryan Beaudreault Date: Wed, 13 Sep 2023 08:23:00 -0400 Subject: [PATCH 2/2] comment --- .../apache/hadoop/hbase/backup/impl/BackupSystemTable.java | 6 ++++++ 1 file changed, 6 insertions(+) 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 aaba41f20891..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 @@ -219,6 +219,9 @@ private void createSystemTable(Admin admin, TableDescriptor descriptor) throws I 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); } } @@ -238,6 +241,9 @@ private void verifyNamespaceExists(Admin admin) throws IOException { 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); } }