Skip to content

Commit 84ccae3

Browse files
authored
HBASE-28079 Unhandled TableExistsException and NamespaceExistException in BackupSystemTable (#5399)
Signed-off-by: Duo Zhang <[email protected]>
1 parent 35667c1 commit 84ccae3

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupSystemTable.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
import org.apache.hadoop.hbase.CellUtil;
4444
import org.apache.hadoop.hbase.HBaseConfiguration;
4545
import org.apache.hadoop.hbase.NamespaceDescriptor;
46+
import org.apache.hadoop.hbase.NamespaceExistException;
4647
import org.apache.hadoop.hbase.ServerName;
48+
import org.apache.hadoop.hbase.TableExistsException;
4749
import org.apache.hadoop.hbase.TableName;
4850
import org.apache.hadoop.hbase.backup.BackupInfo;
4951
import org.apache.hadoop.hbase.backup.BackupInfo.BackupState;
@@ -202,17 +204,28 @@ private void checkSystemTable() throws IOException {
202204
Configuration conf = connection.getConfiguration();
203205
if (!admin.tableExists(tableName)) {
204206
TableDescriptor backupHTD = BackupSystemTable.getSystemTableDescriptor(conf);
205-
admin.createTable(backupHTD);
207+
createSystemTable(admin, backupHTD);
206208
}
207209
if (!admin.tableExists(bulkLoadTableName)) {
208210
TableDescriptor blHTD = BackupSystemTable.getSystemTableForBulkLoadedDataDescriptor(conf);
209-
admin.createTable(blHTD);
211+
createSystemTable(admin, blHTD);
210212
}
211213
waitForSystemTable(admin, tableName);
212214
waitForSystemTable(admin, bulkLoadTableName);
213215
}
214216
}
215217

218+
private void createSystemTable(Admin admin, TableDescriptor descriptor) throws IOException {
219+
try {
220+
admin.createTable(descriptor);
221+
} catch (TableExistsException e) {
222+
// swallow because this class is initialized in concurrent environments (i.e. bulkloads),
223+
// so may be subject to race conditions where one caller succeeds in creating the
224+
// table and others fail because it now exists
225+
LOG.debug("Table {} already exists, ignoring", descriptor.getTableName(), e);
226+
}
227+
}
228+
216229
private void verifyNamespaceExists(Admin admin) throws IOException {
217230
String namespaceName = tableName.getNamespaceAsString();
218231
NamespaceDescriptor ns = NamespaceDescriptor.create(namespaceName).build();
@@ -225,7 +238,14 @@ private void verifyNamespaceExists(Admin admin) throws IOException {
225238
}
226239
}
227240
if (!exists) {
228-
admin.createNamespace(ns);
241+
try {
242+
admin.createNamespace(ns);
243+
} catch (NamespaceExistException e) {
244+
// swallow because this class is initialized in concurrent environments (i.e. bulkloads),
245+
// so may be subject to race conditions where one caller succeeds in creating the
246+
// namespace and others fail because it now exists
247+
LOG.debug("Namespace {} already exists, ignoring", ns.getName(), e);
248+
}
229249
}
230250
}
231251

0 commit comments

Comments
 (0)