apache/hadoop · error · AlreadyBeingCreatedException

Failed to {} {} for {} on {} because this file lease is curr

Error message

Failed to {} {} for {} on {} because this file lease is currently owned by {} on {}

What it means

The file's lease is alive, held by a different client, and has not passed the soft limit, so pre-emption is refused: AlreadyBeingCreatedException('this file lease is currently owned by <client> on <machine>.') — HDFS enforces single-writer semantics until the holder's lease lapses, is released, or is recovered.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java:3029

          LOG.info("startFile: recover " + lease + ", src=" + src + " client "
              + clientName);
          if (internalReleaseLease(lease, src, iip, null)) {
            return true;
          } else {
            throw new RecoveryInProgressException(
                op.getExceptionMessage(src, holder, clientMachine,
                    "lease recovery is in progress. Try again later."));
          }
        } else {
          final BlockInfo lastBlock = file.getLastBlock();
          if (lastBlock != null
              && lastBlock.getBlockUCState() == BlockUCState.UNDER_RECOVERY) {
            throw new RecoveryInProgressException(
                op.getExceptionMessage(src, holder, clientMachine,
                    "another recovery is in progress by "
                        + clientName + " on " + uc.getClientMachine()));
          } else {
            throw new AlreadyBeingCreatedException(
                op.getExceptionMessage(src, holder, clientMachine,
                    "this file lease is currently owned by "
                        + clientName + " on " + uc.getClientMachine()));
          }
        }
      }
    } else {
      return true;
     }
  }

  /**
   * Append to an existing file in the namespace.
   */
  LastBlockWithStatus appendFile(String srcArg, String holder,
      String clientMachine, EnumSet<CreateFlag> flag, boolean logRetryCache)
      throws IOException {
    final String operationName = "append";

View on GitHub (pinned to 2add963021)

Solutions

  1. Stop the current holder — its lease releases on clean close, or lapses at the soft limit after death — then retry
  2. If the holder is known-dead, call recoverLease(path): the NN recovers at/after the soft limit and closes the file; then append or re-create
  3. Adopt unique output paths plus atomic rename so two writers can never collide

Example fix

// before
FSDataOutputStream out = fs.create(path, true);   // owned by another client
// after
DistributedFileSystem dfs = (DistributedFileSystem) fs;
if (!dfs.isFileClosed(path)) { dfs.recoverLease(path); }
while (!dfs.isFileClosed(path)) { Thread.sleep(5000L); }
FSDataOutputStream out = fs.append(path);   // or fs.create(path, true)
Defensive patterns

Strategy: try-catch

Validate before calling

DistributedFileSystem dfs = (DistributedFileSystem) fs;
if (!dfs.isFileClosed(path)) { dfs.recoverLease(path); /* recovers at/after the 60s soft limit */ }

Try / catch

catch (AlreadyBeingCreatedException e) { if (e.getMessage() != null && e.getMessage().contains("currently owned by")) { dfs.recoverLease(src); waitForCloseThenAppend(); } else throw e; }

Prevention

When it happens

Trigger: A second writer calls create/append on a file whose lease is being actively renewed by clientName from another machine, within dfs.namenode.lease-soft-limit-sec (default 60s) of the last renewal, with the last block not under recovery.

Common situations: Duplicate app instances pointed at the same output file; a stuck-but-alive previous writer still renewing; deployment scripts that restart a job while the old instance still heartbeats.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/74cda6784ab4d91f. Report an issue: GitHub.