{"record":{"id":"c528dc12731792de","repo":"apache/hadoop","slug":"metafile-is-empty-r-r","errorCode":null,"errorMessage":"Metafile is empty, r={r}","messagePattern":"Metafile is empty, r=(.+?)","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/FsDatasetImpl.java","lineNumber":2342,"sourceCode":"  }\n\n  /** Check the files of a replica. */\n  static void checkReplicaFiles(final ReplicaInfo r) throws IOException {\n    //check replica's data exists\n    if (!r.blockDataExists()) {\n      throw new FileNotFoundException(\"Block data not found, r=\" + r);\n    }\n    if (r.getBytesOnDisk() != r.getBlockDataLength()) {\n      throw new IOException(\"Block length mismatch, len=\"\n          + r.getBlockDataLength() + \" but r=\" + r);\n    }\n\n    //check replica's meta file\n    if (!r.metadataExists()) {\n      throw new IOException(r.getMetadataURI() + \" does not exist, r=\" + r);\n    }\n    if (r.getMetadataLength() == 0) {\n      throw new IOException(\"Metafile is empty, r=\" + r);\n    }\n  }\n\n  /**\n   * We're informed that a block is no longer valid. Delete it.\n   */\n  @Override // FsDatasetSpi\n  public void invalidate(String bpid, Block invalidBlks[]) throws IOException {\n    invalidate(bpid, invalidBlks, true);\n  }\n\n  private void invalidate(String bpid, Block[] invalidBlks, boolean async)\n      throws IOException {\n    final List<String> errors = new ArrayList<String>();\n    for (int i = 0; i < invalidBlks.length; i++) {\n      final ReplicaInfo info;\n      final FsVolumeImpl v;\n      try (AutoCloseableLock lock = lockManager.readLock(LockLevel.BLOCK_POOl, bpid)) {","sourceCodeStart":2324,"sourceCodeEnd":2360,"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#L2324-L2360","documentation":"IOException thrown by FsDatasetImpl.checkReplicaFiles when the replica's meta (checksum) file exists but is zero bytes (getMetadataLength() == 0). An empty .meta file lacks the checksum header (version + checksum type), so checksums cannot be parsed and the replica cannot be recovered, validated, or finalized safely.","triggerScenarios":"checkReplicaFiles(r) during recovery/finalize where the .meta file was created but its header was never written - typical of a crash between FileOutputStream create and the first flush of the meta header.","commonSituations":"Hard crash / power loss at the moment a block transfer started writing its meta file; disk that reports successful writes but loses them; interrupted backup restore truncating meta files.","solutions":["Treat the replica as corrupt: use hdfs fsck to confirm other replicas exist, then invalidate this replica for re-replication.","If unique, salvage data via recoverLease and read with checksum verification disabled, accepting risk.","Investigate crash-consistency: enable/verify journaling filesystems, check UPS/battery on RAID cache.","Restart the DataNode after fixing the underlying storage reliability issue."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"boolean isEmptyMetaFile(IOException e) {\n  return e.getMessage() != null && e.getMessage().startsWith(\"Metafile is empty\");\n}","tryCatchPattern":"try {\n  dataset.initReplicaRecovery(rBlock);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Metafile is empty\")) {\n    // unreadable checksums: drop this replica from recovery set, verify others via fsck\n    return recoverFromOtherReplicas(rBlock);\n  }\n  throw e;\n}","preventionTips":["Use power-loss-protected write caches; empty meta files are classic post-crash artifacts.","After power events, run hdfs fsck before admitting heavy traffic.","Do not hand-edit or recreate .meta files; let re-replication rebuild clean copies."],"tags":["hdfs","datanode","replica-files","checksum-meta","corruption"],"backgroundTag":"corrupt-checksum-metadata","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}