{"record":{"id":"20d419ad57ccaf55","repo":"apache/hadoop","slug":"replica-does-not-exist-b","errorCode":null,"errorMessage":"Replica does not exist {b}","messagePattern":"Replica does not exist (.+?)","errorType":"exception","errorClass":"ReplicaNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java","lineNumber":1819,"sourceCode":"  @Override // FsDatasetSpi\n  public ReplicaInPipeline convertTemporaryToRbw(\n      final ExtendedBlock b) throws IOException {\n    long startTimeMs = Time.monotonicNow();\n    try (AutoCloseableLock lock = lockManager.writeLock(LockLevel.DIR,\n        b.getBlockPoolId(), getStorageUuidForLock(b),\n        datasetSubLockStrategy.blockIdToSubLock(b.getBlockId()))) {\n      final long blockId = b.getBlockId();\n      final long expectedGs = b.getGenerationStamp();\n      final long visible = b.getNumBytes();\n      LOG.info(\"Convert \" + b + \" from Temporary to RBW, visible length=\"\n          + visible);\n\n      final ReplicaInfo temp;\n      {\n        // get replica\n        final ReplicaInfo r = volumeMap.get(b.getBlockPoolId(), blockId);\n        if (r == null) {\n          throw new ReplicaNotFoundException(\n              ReplicaNotFoundException.NON_EXISTENT_REPLICA + b);\n        }\n        // check the replica's state\n        if (r.getState() != ReplicaState.TEMPORARY) {\n          throw new ReplicaAlreadyExistsException(\n              \"r.getState() != ReplicaState.TEMPORARY, r=\" + r);\n        }\n        temp = r;\n      }\n      // check generation stamp\n      if (temp.getGenerationStamp() != expectedGs) {\n        throw new ReplicaAlreadyExistsException(\n            \"temp.getGenerationStamp() != expectedGs = \" + expectedGs\n                + \", temp=\" + temp);\n      }\n\n      // TODO: check writer?\n      // set writer to the current thread","sourceCodeStart":1801,"sourceCodeEnd":1837,"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#L1801-L1837","documentation":"When a write pipeline is set up on a DataNode whose replica is TEMPORARY (e.g. created by a datanode-to-datanode transfer), FsDatasetImpl looks the replica up in the volumeMap before converting it to RBW. If no entry exists for the blockPoolId+blockId, ReplicaNotFoundException with the NON_EXISTENT_REPLICA prefix is thrown: the DN is asked to convert a replica it does not have.","triggerScenarios":"Pipeline setup targeting a DN whose temporary replica vanished from the volumeMap: the DN restarted (temp replicas are re-scanned or discarded during startup), the replica was invalidated, or the located block is stale and this DN never held the block.","commonSituations":"Client using stale located blocks after DN restart or topology changes; race between replica invalidation and pipeline rebuild; temp replica deleted by the directory scanner.","solutions":["Client refreshes block locations and rebuilds the pipeline on current DNs - usually self-heals","Verify the DN re-registered its storage and replicas after any restart","If the block is missing everywhere, use 'hdfs fsck' and NN logs to decide between re-replication and loss","Re-open the file on the client to discard stale pipeline state"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"Replica r = fsDataset.getReplica(b.getBlockPoolId(), b.getBlockId());\nif (r == null) {\n  rebuildPipelineExcludingThisDatanode(); // wrong DN or replica vanished\n  return;\n}\nfsDataset.convertTemporaryToRbw(b, visible);","typeGuard":"boolean replicaExists(FsDatasetSpi data, ExtendedBlock b) throws IOException {\n  return data.getReplica(b.getBlockPoolId(), b.getBlockId()) != null;\n}","tryCatchPattern":"catch (ReplicaNotFoundException rnfe) {\n  if (rnfe.getMessage().contains(ReplicaNotFoundException.NON_EXISTENT_REPLICA)) {\n    pipeline = refreshLocatedBlocksAndRebuild(); // exclude this DN, retry elsewhere\n  } else { throw rnfe; }\n}","preventionTips":["Fetch fresh LocatedBlocks before every pipeline rebuild instead of reusing the old DN list","Give restarted DataNodes time to re-register replicas before directing recovery at them","Treat NON_EXISTENT_REPLICA as 'wrong DN, retry elsewhere', not as fatal corruption"],"tags":["hdfs","datanode","block-write","replica-not-found","temporary-replica"],"backgroundTag":"hdfs-replica-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}