{"record":{"id":"cd5004491771bf92","repo":"apache/hadoop","slug":"the-file-belonged-to-does-not-exist-or-it-is-no","errorCode":null,"errorMessage":"The file {} belonged to does not exist or it is not under construction.","messagePattern":"The file (.+?) belonged to does not exist or it is not under construction\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java","lineNumber":6049,"sourceCode":"    assert hasWriteLock(RwLockMode.GLOBAL);\n    checkNameNodeSafeMode(\"Cannot get a new generation stamp and an \"\n        + \"access token for block \" + block);\n    \n    // check stored block state\n    BlockInfo storedBlock = getStoredBlock(ExtendedBlock.getLocalBlock(block));\n    if (storedBlock == null) {\n      throw new IOException(block + \" does not exist.\");\n    }\n    if (storedBlock.getBlockUCState() != BlockUCState.UNDER_CONSTRUCTION) {\n      throw new IOException(\"Unexpected BlockUCState: \" + block\n          + \" is \" + storedBlock.getBlockUCState()\n          + \" but not \" + BlockUCState.UNDER_CONSTRUCTION);\n    }\n    \n    // check file inode\n    final INodeFile file = getBlockCollection(storedBlock);\n    if (file == null || !file.isUnderConstruction() || isFileDeleted(file)) {\n      throw new IOException(\"The file \" + storedBlock + \n          \" belonged to does not exist or it is not under construction.\");\n    }\n    \n    // check lease\n    if (clientName == null\n        || !clientName.equals(file.getFileUnderConstructionFeature()\n            .getClientName())) {\n      throw new LeaseExpiredException(\"Lease mismatch: \" + block + \n          \" is accessed by a non lease holder \" + clientName); \n    }\n\n    return file;\n  }\n  \n  /**\n   * Client is reporting some bad block locations.\n   */\n  void reportBadBlocks(LocatedBlock[] blocks) throws IOException {","sourceCodeStart":6031,"sourceCodeEnd":6067,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java#L6031-L6067","documentation":"checkUCBlock resolved the block's inode but the file is null, closed, or deleted, so it is not under construction and cannot accept block updates. The write session the caller believes is active has already ended (typically via lease recovery or completion).","triggerScenarios":"updateBlock/nextGenerationStamp after the file was completed by another attempt, recovered by another client, or deleted while its block remained temporarily.","commonSituations":"Stale writers resuming after lease hard-limit expiry; duplicate task attempts where the first already closed the file.","solutions":["Check isFileClosed(path); if closed, restart via append if more data must be written","Have the writer renew its lease (keep writing or keepalive) so recovery cannot steal the file","Eliminate duplicate writers on the same path"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (dfs.isFileClosed(path)) {\n  throw new IllegalStateException(\"File closed; reopen with append before block updates\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  updateBlock(oldBlock, clientName, ...);\n} catch (IOException e) {\n  if (e.getMessage().contains(\"not under construction\")) {\n    recoverAndWaitThenAppend(path); // lease lost elsewhere: re-establish write\n  } else { throw e; }\n}","preventionTips":["Keep the writer's lease renewed during idle periods","Check isFileClosed before resuming writes after long pauses"],"tags":["hdfs","namenode","lease","block-state","file-closed"],"backgroundTag":"invalid-state-transition","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}