{"record":{"id":"b0a1a6bed9b1bd9e","repo":"apache/hadoop","slug":"block-pool-bpid-is-not-found","errorCode":null,"errorMessage":"Block pool {bpid} is not found","messagePattern":"Block pool (.+?) is not found","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/security/token/block/BlockPoolTokenSecretManager.java","lineNumber":56,"sourceCode":"    SecretManager<BlockTokenIdentifier> {\n  \n  private final Map<String, BlockTokenSecretManager> map =\n      new ConcurrentHashMap<>();\n\n  /**\n   * Add a block pool Id and corresponding {@link BlockTokenSecretManager} to map\n   * @param bpid block pool Id\n   * @param secretMgr {@link BlockTokenSecretManager}\n   */\n  public void addBlockPool(String bpid, BlockTokenSecretManager secretMgr) {\n    map.put(bpid, secretMgr);\n  }\n\n  @VisibleForTesting\n  public BlockTokenSecretManager get(String bpid) {\n    BlockTokenSecretManager secretMgr = map.get(bpid);\n    if (secretMgr == null) {\n      throw new IllegalArgumentException(\n          \"Block pool \" + bpid + \" is not found\");\n    }\n    return secretMgr;\n  }\n  \n  public boolean isBlockPoolRegistered(String bpid) {\n    return map.containsKey(bpid);\n  }\n\n  /** Return an empty BlockTokenIdentifer */\n  @Override\n  public BlockTokenIdentifier createIdentifier() {\n    return new BlockTokenIdentifier();\n  }\n\n  @Override\n  public byte[] createPassword(BlockTokenIdentifier identifier) {\n    return get(identifier.getBlockPoolId()).createPassword(identifier);","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/security/token/block/BlockPoolTokenSecretManager.java#L38-L74","documentation":"BlockPoolTokenSecretManager.get(bpid) throws IllegalArgumentException when asked for the BlockTokenSecretManager of a block pool id that was never registered via addBlockPool. The manager is a bpid -> secret manager map keyed at DN/NN startup as block pools are initialized; querying an unknown bpid means the caller is handling blocks or tokens for a pool this process does not know about.","triggerScenarios":"get(bpid) is called (e.g., during block token generation or validation in tests, or via BlockPoolTokenSecretManager public API) before addBlockPool for that bpid ran, or with a typo'd/wrong bpid. In production NN code the bpid comes from the namespace; in tests it is frequently a hardcoded string.","commonSituations":"Unit tests using a fake/typo'd block pool id (e.g., 'BP-123' vs the real generated 'BP-<random>-<ts>') without registering it; calling token APIs during DataNode init before registerBlockPool; reading a block from an old cluster's storage dir after re-registration; mixed-up test fixtures reusing a stale bpid.","solutions":["Register the pool first: call addBlockPool(bpid, secretManager) (in DN terms, ensure the BPOfferService for that pool completed initialization) before any get().","Verify the bpid string matches the actual pool — print FsDatasetTestUtil/cluster.getBlockPoolId() in tests instead of hardcoding.","Guard call sites with isBlockPoolRegistered(bpid) and skip/handle unknown pools gracefully.","If a stale storage dir for a removed namespace is involved, clear the stale BP directory under the DataNode storage so the unknown pool is not surfaced again."],"exampleFix":"// before\nBlockTokenSecretManager sm = bpTokenSecretManager.getBlockTokenSecretManager(\"BP-fake\");\n// IllegalArgumentException: Block pool BP-fake is not found\n\n// after\nif (bpTokenSecretManager.isBlockPoolRegistered(bpid)) {\n  BlockTokenSecretManager sm = bpTokenSecretManager.getBlockTokenSecretManager(bpid);\n} else {\n  bpTokenSecretManager.addBlockPool(bpid, new BlockTokenSecretManager(...));\n}","handlingStrategy":"validation","validationCode":"if (!bpTokenSecretManager.isBlockPoolRegistered(bpid)) {\n  // unknown pool: register it or reject the request before calling get()\n  throw new UnknownBlockPoolException(bpid);\n}\nBlockTokenSecretManager sm = bpTokenSecretManager.getBlockTokenSecretManager(bpid);","typeGuard":null,"tryCatchPattern":"try {\n  BlockTokenSecretManager sm = bpTokenSecretManager.getBlockTokenSecretManager(bpid);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().endsWith(\"is not found\")) {\n    // handle unknown block pool: log bpid, skip/reject block op\n  } else { throw e; }\n}","preventionTips":["Register block pools (addBlockPool) during BPOfferService init before serving any token ops.","In tests, derive bpid from the running cluster (cluster.getBlockPoolId()) instead of hardcoding.","Guard every get(bpid) with isBlockPoolRegistered(bpid)."],"tags":["hdfs","block-token","security","block-pool","data-node"],"backgroundTag":"unknown-block-pool","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}