{"record":{"id":"ebf194121919fb1e","repo":"apache/hadoop","slug":"failed-to-parse-generation-stamp-blockfile-block","errorCode":null,"errorMessage":"Failed to parse generation stamp: blockFile={blockFile}, metaFile={metaFile}","messagePattern":"Failed to parse generation stamp: blockFile=(.+?), metaFile=(.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetUtil.java","lineNumber":194,"sourceCode":"      String metaFile = listdir[index + 1].getName();\n      if (metaFile.startsWith(blockName)) {\n        return Block.getGenerationStamp(metaFile);\n      }\n    }\n    FsDatasetImpl.LOG.warn(\"Block \" + blockFile + \" does not have a metafile!\");\n    return HdfsConstants.GRANDFATHER_GENERATION_STAMP;\n  }\n\n  /** Find the corresponding meta data file from a given block file */\n  static long parseGenerationStamp(File blockFile, File metaFile\n      ) throws IOException {\n    final String metaname = metaFile.getName();\n    final String gs = metaname.substring(blockFile.getName().length() + 1,\n        metaname.length() - Block.METADATA_EXTENSION.length());\n    try {\n      return Long.parseLong(gs);\n    } catch(NumberFormatException nfe) {\n      throw new IOException(\"Failed to parse generation stamp: blockFile=\"\n          + blockFile + \", metaFile=\" + metaFile, nfe);\n    }\n  }\n\n  /**\n   * Compute the checksum for a block file that does not already have\n   * its checksum computed, and save it to dstMeta file.\n   */\n  public static void computeChecksum(File srcMeta, File dstMeta,\n      File blockFile, int smallBufferSize, Configuration conf)\n          throws IOException {\n    Preconditions.checkNotNull(srcMeta);\n    Preconditions.checkNotNull(dstMeta);\n    Preconditions.checkNotNull(blockFile);\n    // Create a dummy ReplicaInfo object pointing to the blockFile.\n    ReplicaInfo wrapper = new FinalizedReplica(0, 0, 0, null, null) {\n      @Override\n      public URI getMetadataURI() {","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetUtil.java#L176-L212","documentation":"FsDatasetUtil.parseGenerationStamp extracts the numeric generation stamp from a meta file name '<blockName>_<gs>.meta'. NumberFormatException wrapped in this IOException means the middle segment is not a long - a file name violating HDFS naming, produced by corruption, foreign tools, or hand-created files.","triggerScenarios":"Manually copied or renamed meta files; mangled filenames on a failing filesystem; legacy names missing the stamp; test fixtures with wrong names.","commonSituations":"Admins moving block files; disk corruption; exotic filesystems (Fuse, NFS) altering names; very old clusters upgraded in place.","solutions":["Rename the offending meta to the correct '<blockName>_<gs>.meta' shape if the true generation stamp is known (it must match the committed stamp).","Otherwise delete the malformed pair (block plus meta) and let re-replication restore the block, then fsck.","Find what writes foreign files into replica dirs and exclude those tools.","Run the DirectoryScanner to reconcile the volume map after cleanup."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (!metaFile.getName().matches(\"^.+_\\d+\\.meta$\")) {\n  // malformed meta name: quarantine the file instead of parsing\n  return;\n}\nlong gs = FsDatasetUtil.parseGenerationStamp(blockFile, metaFile);","typeGuard":"static boolean hasValidMetaName(File f) {\n  return f != null && f.getName().matches(\"^.+_\\d+\\.meta$\");\n}","tryCatchPattern":"try {\n  long gs = FsDatasetUtil.parseGenerationStamp(blockFile, metaFile);\n} catch (IOException e) {\n  // malformed name: quarantine the block/meta pair\n}","preventionTips":["Build meta names only via DatanodeUtil.getMetaName; never hand-edit replica file names.","Keep foreign tools away from replica directories.","Validate names during test fixture setup, not at parse time."],"tags":["hdfs","datanode","file-naming","generation-stamp","metadata"],"backgroundTag":"hdfs-invalid-block-file-name","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}