{"record":{"id":"ac4d2e2522096b4f","repo":"apache/hadoop","slug":"trying-to-delete-non-existant-block","errorCode":null,"errorMessage":"Trying to delete non-existant block {}","messagePattern":"Trying to delete non-existant block (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java","lineNumber":1189,"sourceCode":"        fsNamesys.getBlockManager().processQueuedMessagesForBlock(newBlock);\n      }\n    }\n    \n    if (newBlocks.length < oldBlocks.length) {\n      // We're removing a block from the file, e.g. abandonBlock(...)\n      if (!file.isUnderConstruction()) {\n        throw new IOException(\"Trying to remove a block from file \" +\n            path + \" which is not under construction.\");\n      }\n      if (newBlocks.length != oldBlocks.length - 1) {\n        throw new IOException(\"Trying to remove more than one block from file \"\n            + path);\n      }\n      Block oldBlock = oldBlocks[oldBlocks.length - 1];\n      boolean removed = FSDirWriteFileOp.unprotectedRemoveBlock(\n          fsDir, path, iip, file, oldBlock);\n      if (!removed && !(op instanceof UpdateBlocksOp)) {\n        throw new IOException(\"Trying to delete non-existant block \" + oldBlock);\n      }\n    } else if (newBlocks.length > oldBlocks.length) {\n      final boolean isStriped = ecPolicy != null;\n      // We're adding blocks\n      for (int i = oldBlocks.length; i < newBlocks.length; i++) {\n        Block newBlock = newBlocks[i];\n        final BlockInfo newBI;\n        if (!op.shouldCompleteLastBlock()) {\n          // TODO: shouldn't this only be true for the last block?\n          // what about an old-version fsync() where fsync isn't called\n          // until several blocks in?\n          if (isStriped) {\n            newBI = new BlockInfoStriped(newBlock, ecPolicy);\n          } else {\n            newBI = new BlockInfoContiguous(newBlock,\n                file.getPreferredBlockReplication());\n          }\n          newBI.convertToBlockUnderConstruction(","sourceCodeStart":1171,"sourceCodeEnd":1207,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java#L1171-L1207","documentation":"After updateBlocks removes the last block via FSDirWriteFileOp.unprotectedRemoveBlock, a false return means the block was not present in the file. UpdateBlocksOp is exempt (its reapplication is tolerated), but any other op throws IOException('Trying to delete non-existant block <block>'; the spelling is in the source). The op names a block the namespace does not hold.","triggerScenarios":"Replaying a block-removal op whose target block is already gone: duplicate replay, image/edits divergence, or corrupted block fields.","commonSituations":"Same replay-inconsistency family: mixed restores, duplicated segments, corruption.","solutions":["Run 'hdfs namenode -recover' to skip the inconsistent transaction","Restore a consistent fsimage plus edits from one backup epoch","Inspect the file's transaction history with 'hdfs oev' to find where the block was already removed"],"exampleFix":"# before: replay fails 'Trying to delete non-existant block blk_123'\nhdfs --daemon start namenode\n\n# after: recover past the duplicate removal\nhdfs namenode -recover","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  loader.loadFSEdits(storage, 0);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"non-existant block\")) {\n    // block already absent: duplicate replay or diverged state; recover or\n    // restore a consistent fsimage+edits pair\n  }\n  throw e;\n}","preventionTips":["Keep one linear segment chain; remove duplicates before restart","Bootstrap standbys from the active instead of copying journals by hand"],"tags":["hdfs","namenode","edit-log","replay","blocks","corruption"],"backgroundTag":"edit-log-replay-inconsistency","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}