{"record":{"id":"536b1e441a3fa6f8","repo":"apache/hadoop","slug":"all-positive-block-ids-are-used-wrapping-to-negat","errorCode":null,"errorMessage":"All positive block IDs are used, wrapping to negative IDs, which might conflict with erasure coded block groups.","messagePattern":"All positive block IDs are used, wrapping to negative IDs, which might conflict with erasure coded block groups\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"critical","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/SequentialBlockIdGenerator.java","lineNumber":58,"sourceCode":"\n  private final BlockManager blockManager;\n\n  SequentialBlockIdGenerator(BlockManager blockManagerRef) {\n    super(LAST_RESERVED_BLOCK_ID);\n    this.blockManager = blockManagerRef;\n  }\n\n  @Override // NumberGenerator\n  public long nextValue() {\n    Block b = new Block(super.nextValue());\n\n    // There may be an occasional conflict with randomly generated\n    // block IDs. Skip over the conflicts.\n    while(isValidBlock(b)) {\n      b.setBlockId(super.nextValue());\n    }\n    if (b.getBlockId() < 0) {\n      throw new IllegalStateException(\"All positive block IDs are used, \" +\n          \"wrapping to negative IDs, \" +\n          \"which might conflict with erasure coded block groups.\");\n    }\n    return b.getBlockId();\n  }\n\n  /**\n   * Returns whether the given block is one pointed-to by a file.\n   */\n  private boolean isValidBlock(Block b) {\n    BlockInfo bi = blockManager.getStoredBlock(b);\n    return bi != null && bi.getBlockCollectionId() !=\n        INodeId.INVALID_INODE_ID;\n  }\n}\n","sourceCodeStart":40,"sourceCodeEnd":74,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/SequentialBlockIdGenerator.java#L40-L74","documentation":"SequentialBlockIdGenerator hands out positive sequential IDs for replicated blocks, skipping any ID already referenced by a stored block (isValidBlock checks blockManager.getStoredBlock and its BlockCollectionId). If the sequence wraps past Long.MAX_VALUE into negative values it throws IllegalStateException, because negative IDs are reserved for erasure-coded block groups. The generator value is journaled, so the state persists across NameNode restarts.","triggerScenarios":"Allocating more than ~2^63 - initial blocks (astronomically large), or a corrupted persisted block generation counter in the fsimage/edits that starts near Long.MAX_VALUE. Thrown inside nextValue() while the NameNode assigns a new block ID for a replicated file write.","commonSituations":"Theoretical for real clusters; occurs with hand-edited or corrupted generation counters, or fault-injection tests that force counter values.","solutions":["Restore the namespace from the last clean fsimage checkpoint to reset the corrupted generation counter","If genuinely exhausted, rebuild the namespace via distcp (export data, reformat, re-import) — the positive long range cannot be extended","Report the case upstream with the fsimage generation values for diagnosis"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  out = fs.create(path);\n} catch (RemoteException re) {\n  if (re.getClassName().endsWith(\"IllegalStateException\")\n      && String.valueOf(re.getMessage()).contains(\"block IDs are used\")) {\n    alertOps(\"Positive block ID space exhausted on NameNode\"); // no client-side workaround; metadata rebuild required\n  } else throw re;\n}","preventionTips":["Monitor the persisted block generation stamp across fsimages for corruption or abnormal jumps","Restore from clean checkpoints rather than editing generation counters","Treat any occurrence as a metadata-integrity incident, not a transient failure"],"tags":["hdfs","block-id","namenode","id-exhaustion","illegal-state"],"backgroundTag":"id-space-exhausted","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}