{"record":{"id":"6637844d1536d194","repo":"apache/hadoop","slug":"blockid-is-not-valid","errorCode":null,"errorMessage":"BlockId {} is not valid.","messagePattern":"BlockId (.+?) is not valid\\.","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java","lineNumber":830,"sourceCode":"  @Override // FsDatasetSpi\n  public long getLength(ExtendedBlock b) throws IOException {\n    return getBlockReplica(b).getBlockDataLength();\n  }\n\n  /**\n   * Get File name for a given block.\n   */\n  private ReplicaInfo getBlockReplica(ExtendedBlock b) throws IOException {\n    return getBlockReplica(b.getBlockPoolId(), b.getBlockId());\n  }\n  \n  /**\n   * Get File name for a given block.\n   */\n  ReplicaInfo getBlockReplica(String bpid, long blockId) throws IOException {\n    ReplicaInfo r = validateBlockFile(bpid, blockId);\n    if (r == null) {\n      throw new FileNotFoundException(\"BlockId \" + blockId + \" is not valid.\");\n    }\n    return r;\n  }\n\n  @Override // FsDatasetSpi\n  public InputStream getBlockInputStream(ExtendedBlock b,\n      long seekOffset) throws IOException {\n\n    ReplicaInfo info;\n    try (AutoCloseableLock lock = lockManager.readLock(LockLevel.DIR,\n        b.getBlockPoolId(), getStorageUuidForLock(b),\n        datasetSubLockStrategy.blockIdToSubLock(b.getBlockId()))) {\n      info = volumeMap.get(b.getBlockPoolId(), b.getLocalBlock());\n    }\n\n    if (info != null && info.getVolume().isTransientStorage()) {\n      ramDiskReplicaTracker.touch(b.getBlockPoolId(), b.getBlockId());\n      datanode.getMetrics().incrRamDiskBlocksReadHits();","sourceCodeStart":812,"sourceCodeEnd":848,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java#L812-L848","documentation":"Thrown as FileNotFoundException from FsDatasetImpl.getBlockReplica(bpid, blockId) when validateBlockFile returns null, i.e. no replica for that blockId exists in the volumeMap for the block pool. It is the lookup primitive behind most read/length/meta operations on a block, so nearly any client read path that reaches the DataNode with a stale or unknown block ID surfaces it.","triggerScenarios":"Calling getBlockInputStream/getMetaDataInputStream/validateBlock-style flows (or getBlockReplica directly) for a (blockPoolId, blockId) that has no entry in volumeMap: block already deleted (NameNode tells a slow client to read it), block invalidated between report cycles, wrong block pool ID, or replica lost with a volume failure.","commonSituations":"Client retries a read after the block was deleted/replaced (lease recovery, truncation); DataNode just recovered from a disk loss so its volumeMap no longer has replicas the NameNode still lists; cross-cluster copy pointing a reader at the wrong cluster/block pool; test harnesses querying random block IDs.","solutions":["Confirm the block still exists NameNode-side: hdfs fsck /path -files -blocks | grep <blockId>, and check whether the file was deleted/replaced under the reader.","Verify the block pool ID matches this DataNode/cluster (VERSION, clusterID/blockpoolID) — a mismatched ExtendedBlock always misses.","If a volume failed, let the DataNode re-register and re-report (or restart it) so the NameNode prunes the missing replicas and re-replicates.","Retry the read from the client with a fresh block-location lookup (getBlockLocations) instead of a cached ExtendedBlock."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Cheap pre-check before read-style APIs: resolve the replica first.\nReplicaInfo r = fsDataset.getReplica(b.getBlockPoolId(), b.getBlockId());\nif (r == null) {\n  // refresh block locations instead of reading a dead ExtendedBlock\n  locatedBlocks = dfsClient.getLocatedBlocks(path, offset, len);\n  return readFrom(locatedBlocks);\n}","typeGuard":null,"tryCatchPattern":"// Distinguish 'no such replica' from other IO problems; refresh locations on it.\ntry {\n  return fsDataset.getBlockInputStream(b, offset);\n} catch (FileNotFoundException e) { // getBlockReplica signals via FNFE\n  LOG.warn(\"Block {} absent on this DN, refreshing locations\", b);\n  return readFromFreshLocations(dfsClient, b);\n}","preventionTips":["Never cache ExtendedBlock/locations across delete-adjacent operations; re-fetch getBlockLocations after file mutations.","Check replica presence via FsDatasetSpi.getReplica(bpid, blkId) before volume-local operations.","Keep DataNode block reports fresh (triggerBlockReport) in test harnesses that mutate blocks directly."],"tags":["hadoop","hdfs","datanode","fsdataset","replica","block-not-found"],"backgroundTag":"replica-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}