4343import org .apache .hadoop .hbase .CellUtil ;
4444import org .apache .hadoop .hbase .HBaseConfiguration ;
4545import org .apache .hadoop .hbase .NamespaceDescriptor ;
46+ import org .apache .hadoop .hbase .NamespaceExistException ;
4647import org .apache .hadoop .hbase .ServerName ;
48+ import org .apache .hadoop .hbase .TableExistsException ;
4749import org .apache .hadoop .hbase .TableName ;
4850import org .apache .hadoop .hbase .backup .BackupInfo ;
4951import 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