{"record":{"id":"96f555c42707e42c","repo":"apache/hadoop","slug":"file-is-deleted-inode","errorCode":null,"errorMessage":"File is deleted: {} (inode {}) {}","messagePattern":"File is deleted: (.+?) \\(inode (.+?)\\) (.+?)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java","lineNumber":3269,"sourceCode":"    assert hasReadLock(RwLockMode.FS);\n    if (inode == null) {\n      throw new FileNotFoundException(\"File does not exist: \"\n          + leaseExceptionString(src, fileId, holder));\n    }\n    if (!inode.isFile()) {\n      throw new LeaseExpiredException(\"INode is not a regular file: \"\n          + leaseExceptionString(src, fileId, holder));\n    }\n    final INodeFile file = inode.asFile();\n    if (!file.isUnderConstruction()) {\n      throw new LeaseExpiredException(\"File is not open for writing: \"\n          + leaseExceptionString(src, fileId, holder));\n    }\n    // No further modification is allowed on a deleted file.\n    // A file is considered deleted, if it is not in the inodeMap or is marked\n    // as deleted in the snapshot feature.\n    if (isFileDeleted(file)) {\n      throw new FileNotFoundException(\"File is deleted: \"\n          + leaseExceptionString(src, fileId, holder));\n    }\n    final String owner = file.getFileUnderConstructionFeature().getClientName();\n    if (holder != null && !owner.equals(holder)) {\n      throw new LeaseExpiredException(\"Client (=\" + holder\n          + \") is not the lease owner (=\" + owner + \": \"\n          + leaseExceptionString(src, fileId, holder));\n    }\n    return file;\n  }\n \n  /**\n   * Complete in-progress write to the given file.\n   * @return true if successful, false if the client should continue to retry\n   *         (e.g if not all blocks have reached minimum replication yet)\n   * @throws IOException on error (eg lease mismatch, file not open, file deleted)\n   */\n  boolean completeFile(final String src, String holder,","sourceCodeStart":3251,"sourceCodeEnd":3287,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java#L3251-L3287","documentation":"Thrown as FileNotFoundException when a lease operation targets an under-construction file whose INode is already gone. FSNamesystem considers a file deleted if it was removed from the inode map or if the snapshot feature marks it deleted (isFileDeleted). The NameNode refuses any further modification of a deleted file, so lease recovery, block allocation, and file completion all fail fast.","triggerScenarios":"Calls that validate the write lease (addBlock, completeFile, recoverLease, abandonBlock, updateBlock) on a path deleted by another client, deleted inside a snapshot, or deleted by the same application while a writer still held the file open.","commonSituations":"A cleanup thread or job committer deletes a temp output while a slow writer is still closing it; MapReduce/Spark speculative tasks racing the output committer; retry loops that keep calling recoverLease on a path already removed; delete-inside-snapshot workflows.","solutions":["Verify the path still exists (fs.exists / getFileStatus) before closing or recovering the lease; if it is gone, treat the write as failed and recreate the file","Audit for concurrent deleters of the same path (other clients, cleaner jobs, committer cleanup) and serialize delete vs. finalize","If snapshots are in play, confirm the file was not deleted within a snapshot that still pins it","After a failover, do not keep retrying the old file handle; restart the write to a new unique path"],"exampleFix":"// before\ntry { dfs.recoverLease(path); } catch (IOException e) { /* blind retry loop */ }\n\n// after\ntry { dfs.recoverLease(path); }\ncatch (FileNotFoundException e) {\n  LOG.warn(\"File was deleted, abandoning write: \" + path);\n  return; // terminal, do not retry\n}","handlingStrategy":"try-catch","validationCode":"Path p = new Path(src);\nif (!fs.exists(p)) {\n  throw new IllegalStateException(\"Refusing lease op; file already deleted: \" + p);\n}","typeGuard":null,"tryCatchPattern":"try {\n  dfs.recoverLease(path); // or complete/close\n} catch (FileNotFoundException e) {\n  // file deleted underneath the writer: terminal, do not retry\n  abandonWrite(path);\n}","preventionTips":["Serialize delete and finalize on the same path in application code","Write to unique temp paths and rename on success so deleters never touch live files","Before closing or recovering, check getFileStatus on the exact path"],"tags":["hdfs","namenode","lease","file-not-found","deleted-file"],"backgroundTag":"file-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}