{"record":{"id":"5b74f6fe008b2ad2","repo":"apache/hadoop","slug":"r-getstate-replicastate-temporary-r-r","errorCode":null,"errorMessage":"r.getState() != ReplicaState.TEMPORARY, r={r}","messagePattern":"r\\.getState\\(\\) != ReplicaState\\.TEMPORARY, r=(.+?)","errorType":"exception","errorClass":"ReplicaAlreadyExistsException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java","lineNumber":1824,"sourceCode":"        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\n      // temp.setWriter(Thread.currentThread());\n\n      // check length\n      final long numBytes = temp.getNumBytes();\n      if (numBytes < visible) {","sourceCodeStart":1806,"sourceCodeEnd":1842,"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#L1806-L1842","documentation":"convertTemporaryToRbw only makes sense for TEMPORARY replicas. If the volumeMap entry for the block exists but is in another state (RBW, FINALIZED, RWR), ReplicaAlreadyExistsException is thrown with the offending state: the requested conversion cannot proceed because the replica has already moved on.","triggerScenarios":"Pipeline setup expecting a temporary replica while the local replica is in a different state - finalized by a concurrent operation, or already converted to RBW by a racing pipeline setup.","commonSituations":"Racing recoveries/pipeline builds hitting the same block; stale located blocks implying a temp replica that has since been finalized; concurrent re-replication converting the replica underneath.","solutions":["Refresh block locations and rebuild the pipeline - the state change usually means the work is already done","Retry once after a pause when caused by racing operations","Run 'hdfs fsck' on the block to verify its final state is consistent","If it persists on one DN, trace that replica's state transitions in DN logs; invalidate it if wedged"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"Replica r = fsDataset.getReplica(b.getBlockPoolId(), b.getBlockId());\nif (r != null && r.getState() != ReplicaState.TEMPORARY) {\n  // replica already moved on (finalized/RBW): rebuild from fresh locations\n  refreshLocatedBlocksAndRebuildPipeline();\n  return;\n}\nfsDataset.convertTemporaryToRbw(b, visible);","typeGuard":"boolean isTemporary(Replica r) {\n  return r != null && r.getState() == ReplicaState.TEMPORARY;\n}","tryCatchPattern":"catch (ReplicaAlreadyExistsException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"TEMPORARY\")) {\n    refreshLocatedBlocksAndRebuildPipeline(); // work usually already done\n  } else { throw e; }\n}","preventionTips":["Do not replay old pipeline setups against DNs whose replica state may have advanced","Serialize recoveries per block; avoid concurrent pipeline builds for the same blockId","Log replica-state transitions on the DN to identify which racing writer changed the state"],"tags":["hdfs","datanode","block-write","replica-state","temporary-replica"],"backgroundTag":"hdfs-replica-state-conflict","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}