private static FanOutOneBlockAsyncDFSOutput createOutput(DistributedFileSystem dfs, String src,
    boolean overwrite, boolean createParent, short replication, long blockSize,
    EventLoopGroup eventLoopGroup, Class<? extends Channel> channelClass, StreamSlowMonitor monitor,
    boolean noLocalWrite) throws IOException {
    Configuration conf = dfs.getConf();
    DFSClient client = dfs.getClient();
    String clientName = client.getClientName();
    ClientProtocol namenode = client.getNamenode();
    int createMaxRetries =
      conf.getInt(ASYNC_DFS_OUTPUT_CREATE_MAX_RETRIES, DEFAULT_ASYNC_DFS_OUTPUT_CREATE_MAX_RETRIES);
    ExcludeDatanodeManager excludeDatanodeManager = monitor.getExcludeDatanodeManager();
    Set<DatanodeInfo> toExcludeNodes =
      new HashSet<>(excludeDatanodeManager.getExcludeDNs().keySet());
    for (int retry = 0;; retry++) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("When create output stream for {}, exclude list is {}, retry={}", src,
          getDataNodeInfo(toExcludeNodes), retry);
      }
      EnumSetWritable<CreateFlag> createFlags = getCreateFlags(overwrite, noLocalWrite);
      HdfsFileStatus stat;
      try {
        stat = FILE_CREATOR.create(namenode, src,
          FsPermission.getFileDefault().applyUMask(FsPermission.getUMask(conf)), clientName,
          createFlags, createParent, replication, blockSize, CryptoProtocolVersion.supported());
      } catch (Exception e) {
        if (e instanceof RemoteException) {
          throw (RemoteException) e;
        } else {
          throw new NameNodeException(e);
        }
      }
      boolean succ = false;
      LocatedBlock locatedBlock = null;
      List<Future<Channel>> futureList = null;
      try {
        DataChecksum summer = createChecksum(client);
        locatedBlock = namenode.addBlock(src, client.getClientName(), null,
          toExcludeNodes.toArray(new DatanodeInfo[0]), stat.getFileId(), null, null);
        Map<Channel, DatanodeInfo> datanodes = new IdentityHashMap<>();
        futureList = connectToDataNodes(conf, client, clientName, locatedBlock, 0L, 0L,
          PIPELINE_SETUP_CREATE, summer, eventLoopGroup, channelClass);
        for (int i = 0, n = futureList.size(); i < n; i++) {
          DatanodeInfo datanodeInfo = getLocatedBlockLocations(locatedBlock)[i];
          try {
            datanodes.put(futureList.get(i).syncUninterruptibly().getNow(), datanodeInfo);
          } catch (Exception e) {
            // exclude the broken DN next time
            toExcludeNodes.add(datanodeInfo);
            excludeDatanodeManager.tryAddExcludeDN(datanodeInfo, "connect error");
            throw e;
          }
        }
        Encryptor encryptor = createEncryptor(conf, stat, client);
        FanOutOneBlockAsyncDFSOutput output =
          new FanOutOneBlockAsyncDFSOutput(conf, dfs, client, namenode, clientName, src, stat,
            createFlags.get(), locatedBlock, encryptor, datanodes, summer, ALLOC, monitor);
        beginFileLease(output);
        succ = true;
        return output;
      } catch (RemoteException e) {
        LOG.warn("create fan-out dfs output {} failed, retry = {}", src, retry, e);
        if (shouldRetryCreate(e)) {
          if (retry >= createMaxRetries) {
            throw e.unwrapRemoteException();
          }
        } else {
          throw e.unwrapRemoteException();
        }
      } catch (IOException e) {
        LOG.warn("create fan-out dfs output {} failed, retry = {}", src, retry, e);
        if (retry >= createMaxRetries) {
          throw e;
        }
        // overwrite the old broken file.
        overwrite = true;
        try {
          Thread.sleep(ConnectionUtils.getPauseTime(100, retry));
        } catch (InterruptedException ie) {
          throw new InterruptedIOException();
        }
      } finally {
        if (!succ) {
          if (futureList != null) {
            for (Future<Channel> f : futureList) {
              addListener(f, new FutureListener<Channel>() {

                @Override
                public void operationComplete(Future<Channel> future) throws Exception {
                  if (future.isSuccess()) {
                    safeClose(future.getNow());
                  }
                }
              });
            }
          }
        }
      }
    }
  }
Exception other than RemoteException thrown when calling create on namenode
hbase-asyncfs/src/main/java/org/apache/hadoop/hbase/io/asyncfs/FanOutOneBlockAsyncDFSOutputHelper.java