{"record":{"id":"1f226d47ee524d82","repo":"apache/hadoop","slug":"temp-getgenerationstamp-expectedgs-expecte","errorCode":null,"errorMessage":"temp.getGenerationStamp() != expectedGs = {expectedGs}, temp={temp}","messagePattern":"temp\\.getGenerationStamp\\(\\) != expectedGs = (.+?), temp=(.+?)","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":1831,"sourceCode":"\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) {\n        throw new IOException(numBytes + \" = numBytes < visible = \"\n            + visible + \", temp=\" + temp);\n      }\n      // check volume\n      final FsVolumeImpl v = (FsVolumeImpl) temp.getVolume();\n      if (v == null) {\n        throw new IOException(\"r.getVolume() = null, temp=\" + temp);","sourceCodeStart":1813,"sourceCodeEnd":1849,"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#L1813-L1849","documentation":"Before converting a TEMPORARY replica to RBW, FsDatasetImpl verifies the replica's generation stamp equals expectedGs taken from the ExtendedBlock. A mismatch (stale or advanced stamp) throws ReplicaAlreadyExistsException, preventing the pipeline from continuing against the wrong block incarnation.","triggerScenarios":"convertTemporaryToRbw where the temp replica's GS differs from the block's GS - typically a recovery bumped the GS after the temp replica was created, and the client is driving a pipeline with mismatched stamps.","commonSituations":"Lease/block recovery racing a replication transfer; stale located blocks carrying an old GS; a client retry mixing ExtendedBlocks from different block incarnations.","solutions":["Refresh located blocks so the GSs match, then retry the conversion/pipeline","Ensure only one recovery incarnation runs at a time for the block","If the temp replica's GS is stale leftovers, invalidate it and let re-replication replace it","Run 'hdfs fsck' to reconcile replica GSs across DNs"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"Replica r = fsDataset.getReplica(b.getBlockPoolId(), b.getBlockId());\nif (r != null && r.getGenerationStamp() != b.getGenerationStamp()) {\n  refetchLocatedBlockAndRebuildPipeline(); // GS moved on; do not convert this temp replica\n  return;\n}\nfsDataset.convertTemporaryToRbw(b, visible);","typeGuard":"boolean gsMatches(Replica r, ExtendedBlock b) {\n  return r != null && r.getGenerationStamp() == b.getGenerationStamp();\n}","tryCatchPattern":"catch (ReplicaAlreadyExistsException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"expectedGs\")) {\n    refetchLocatedBlockAndRetryOnce();\n  } else { throw e; }\n}","preventionTips":["Never mix generation stamps across retries: pair the ExtendedBlock's GS with the exact replica being targeted","Re-fetch located blocks after any lease-recovery event before opening pipelines","Run only one recovery incarnation per block at a time"],"tags":["hdfs","datanode","block-write","generation-stamp","temporary-replica"],"backgroundTag":"hdfs-generation-stamp-mismatch","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}