{"record":{"id":"41e1510d9d7b9e4d","repo":"apache/hadoop","slug":"unexpected-blockpoolid-blockpoolid-expected-b","errorCode":null,"errorMessage":"Unexpected BlockPoolId <blockPoolId> - expected <bpId>","messagePattern":"Unexpected BlockPoolId <blockPoolId> - expected <bpId>","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirWriteFileOp.java","lineNumber":148,"sourceCode":"\n    Block localBlock = ExtendedBlock.getLocalBlock(b);\n    fsd.writeLock();\n    try {\n      // Remove the block from the pending creates list\n      if (!unprotectedRemoveBlock(fsd, src, iip, file, localBlock)) {\n        return;\n      }\n    } finally {\n      fsd.writeUnlock();\n    }\n    persistBlocks(fsd, src, file, false);\n  }\n\n  static void checkBlock(FSNamesystem fsn, ExtendedBlock block)\n      throws IOException {\n    String bpId = fsn.getBlockPoolId();\n    if (block != null && !bpId.equals(block.getBlockPoolId())) {\n      throw new IOException(\"Unexpected BlockPoolId \" + block.getBlockPoolId()\n          + \" - expected \" + bpId);\n    }\n  }\n\n  /**\n   * Part I of getAdditionalBlock().\n   * Analyze the state of the file under read lock to determine if the client\n   * can add a new block, detect potential retries, lease mismatches,\n   * and minimal replication of the penultimate block.\n   *\n   * Generate target DataNode locations for the new block,\n   * but do not create the new block yet.\n   */\n  static ValidateAddBlockResult validateAddBlock(\n      FSNamesystem fsn, FSPermissionChecker pc,\n      String src, long fileId, String clientName,\n      ExtendedBlock previous, LocatedBlock[] onRetryBlock) throws IOException {\n    final long blockSize;","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirWriteFileOp.java#L130-L166","documentation":"FSDirWriteFileOp.checkBlock verifies that an ExtendedBlock a client presents (for example to completeFile or getAdditionalBlock) carries the same block pool id as the NameNode namespace it is talking to. A mismatch means the client is presenting a block belonging to a different HDFS namespace, so the NameNode refuses the operation rather than update state for a foreign block.","triggerScenarios":"completeFile/addBlock RPCs that include a block whose BPID differs from the target NameNode's BPID: client built from the wrong fs.defaultFS, ViewFS mount table routing to the wrong nameservice, or a client holding blocks from cluster A while talking to cluster B.","commonSituations":"Cluster migration or restore from backup producing a new block pool id while old clients keep running; HA pair where one NameNode was reformatted and diverged from shared edits; federated/ViewFS misroutes between subclusters.","solutions":["Verify the client's fs.defaultFS and ViewFS mount tables point at the nameservice that owns the block; compare the blockpoolid in the NameNode VERSION file with the block's BPID","If an HA NameNode has a divergent BPID, re-bootstrap or reformat the stray NameNode from the shared edits so both nodes share one namespace","After restores or migrations, restart long-lived clients and jobs so block references and configuration agree"],"exampleFix":"<!-- before: client writing to the wrong subcluster -->\n<property><name>fs.defaultFS</name><value>hdfs://nsA</value></property>\n\n<!-- after: route to the nameservice owning the block pool -->\n<property><name>fs.defaultFS</name><value>hdfs://nsB</value></property>","handlingStrategy":"validation","validationCode":"URI expected = URI.create(\"hdfs://nsB\");\nif (!fs.getUri().equals(expected)) {\n  throw new IllegalStateException(\n      \"Connected to \" + fs.getUri() + \" but blocks belong to \" + expected);\n}","typeGuard":null,"tryCatchPattern":"try {\n  namenode.complete(src, clientName, last, fileId);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"Unexpected BlockPoolId\")) {\n    // stop retrying: this client is wired to the wrong namespace\n    throw new IllegalStateException(\"Wrong nameservice for this block pool\", e);\n  }\n  throw e;\n}","preventionTips":["Pin fs.defaultFS / HA nameservice per environment; never mix client configs across clusters","Restart long-lived clients after cluster restores so blocks and config agree","In federated (ViewFS) setups, verify mount table entries route writes to the owning subcluster"],"tags":["hdfs","federation","block-pool","misconfiguration","ha"],"backgroundTag":"block-pool-id-mismatch","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}