{"record":{"id":"2d4de75c9b4a9462","repo":"apache/hadoop","slug":"file-does-not-exist-inode","errorCode":null,"errorMessage":"File does not exist: {} (inode {}) {}","messagePattern":"File does not exist: (.+?) \\(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":3253,"sourceCode":"    } finally {\n      writeUnlock(RwLockMode.GLOBAL, operationName);\n    }\n    getEditLog().logSync();\n  }\n\n  private String leaseExceptionString(String src, long fileId, String holder) {\n    final Lease lease = leaseManager.getLease(holder);\n    return src + \" (inode \" + fileId + \") \" + (lease != null? lease.toString()\n        : \"Holder \" + holder + \" does not have any open files.\");\n  }\n\n  INodeFile checkLease(INodesInPath iip, String holder, long fileId)\n      throws LeaseExpiredException, FileNotFoundException {\n    String src = iip.getPath();\n    INode inode = iip.getLastINode();\n    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    }","sourceCodeStart":3235,"sourceCodeEnd":3271,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java#L3235-L3271","documentation":"checkLease — the guard for addBlock/abandonBlock/close/recoverLease on a held lease — resolved the path but iip.getLastINode() is null: the file was deleted from the namespace while the client still held its lease. FileNotFoundException('File does not exist: ...') includes the inode id and the holder's lease state for diagnosis.","triggerScenarios":"A writer streams to a file that another actor deletes mid-write (user rm, cleanup job, trash purge, rename-overwrite); the writer's next addBlock/close/recoverLease then hits the missing inode.","commonSituations":"Concurrent cleanup jobs deleting temp/part files still being written; a user deletes a file an ETL is streaming into; a directory is deleted after a job was preempted but before its close.","solutions":["Abort this stream and restart the output under a fresh path — the target is gone","Coordinate lifecycle: writers own their temp paths; cleaners only delete paths that are closed (check DistributedFileSystem#isFileClosed)","Find who deleted it: the NameNode audit log records the delete RPC with user, path, and time"],"exampleFix":"// before\nout.close();   // or out.write -> FileNotFoundException mid-stream\n// after\ntry { out.close(); }\ncatch (FileNotFoundException e) {\n  LOG.error(\"output deleted mid-write: {}\", path);\n  restartWriteUnder(newPath);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"catch (FileNotFoundException e) { // target deleted mid-write: abort this stream, re-create under a new name, rewrite from last committed offset }","preventionTips":["Use the own-and-rename pattern: write to a private temp path, rename on success","Never point cleanup jobs at paths that may be under active lease (check isFileClosed first)"],"tags":["hdfs","lease","file-deleted","filenotfound","concurrent-write"],"backgroundTag":"file-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}