private void checkAndCreateTable(Connection conn, TableName targetTableName,
    ArrayList<Path> regionDirList, TableDescriptor htd, boolean truncateIfExists)
    throws IOException {
    try (Admin admin = conn.getAdmin()) {
      boolean createNew = false;
      if (admin.tableExists(targetTableName)) {
        if (truncateIfExists) {
          LOG.info(
            "Truncating exising target table '" + targetTableName + "', preserving region splits");
          admin.disableTable(targetTableName);
          admin.truncateTable(targetTableName, true);
        } else {
          LOG.info("Using exising target table '" + targetTableName + "'");
        }
      } else {
        createNew = true;
      }
      if (createNew) {
        LOG.info("Creating target table '" + targetTableName + "'");
        byte[][] keys = null;
        try {
          if (regionDirList == null || regionDirList.size() == 0) {
            admin.createTable(htd);
          } else {
            keys = generateBoundaryKeys(regionDirList);
            if (keys.length > 0) {
              // create table using table descriptor and region boundaries
              admin.createTable(htd, keys);
            } else {
              admin.createTable(htd);
            }
          }
        } catch (NamespaceNotFoundException e) {
          LOG.warn("There was no namespace and the same will be created");
          String namespaceAsString = targetTableName.getNamespaceAsString();
          LOG.info("Creating target namespace '" + namespaceAsString + "'");
          admin.createNamespace(NamespaceDescriptor.create(namespaceAsString).build());
          if (null == keys) {
            admin.createTable(htd);
          } else {
            admin.createTable(htd, keys);
          }
        }

      }
      long startTime = EnvironmentEdgeManager.currentTime();
      while (!admin.isTableAvailable(targetTableName)) {
        try {
          Thread.sleep(100);
        } catch (InterruptedException ie) {
          Thread.currentThread().interrupt();
        }
        if (EnvironmentEdgeManager.currentTime() - startTime > TABLE_AVAILABILITY_WAIT_TIME) {
          throw new IOException("Time out " + TABLE_AVAILABILITY_WAIT_TIME + "ms expired, table "
            + targetTableName + " is still not available");
        }
      }
    }
  }
Prepare the table for bulkload, most codes copied from {@code createTable} method in
{@code BulkLoadHFilesTool}.
@param conn             connection
@param targetTableName  target table name
@param regionDirList    region directory list
@param htd              table descriptor
@param truncateIfExists truncates table if exists
@throws IOException exception
hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/util/RestoreTool.java