{"record":{"id":"e17e785e1043328d","repo":"apache/hadoop","slug":"eof-while-reading-layout-flags-from-log","errorCode":null,"errorMessage":"EOF while reading layout flags from log","messagePattern":"EOF while reading layout flags from log","errorType":"exception","errorClass":"LogHeaderCorruptException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EditLogFileInputStream.java","lineNumber":183,"sourceCode":"      }\n      if (logVersion == -1) {\n        // The edits in progress file is pre-allocated with 1MB of \"-1\" bytes\n        // when it is created, then the header is written. If the header is\n        // -1, it indicates the an exception occurred pre-allocating the file\n        // and the header was never written. Therefore this is effectively a\n        // corrupt and empty log.\n        throw new LogHeaderCorruptException(\"No header present in log (value \" +\n            \"is -1), probably due to disk space issues when it was created. \" +\n            \"The log has no transactions and will be sidelined.\");\n      }\n      // We assume future layout will also support ADD_LAYOUT_FLAGS\n      if (NameNodeLayoutVersion.supports(\n          LayoutVersion.Feature.ADD_LAYOUT_FLAGS, logVersion) ||\n          logVersion < NameNodeLayoutVersion.CURRENT_LAYOUT_VERSION) {\n        try {\n          LayoutFlags.read(dataIn);\n        } catch (EOFException eofe) {\n          throw new LogHeaderCorruptException(\"EOF while reading layout \" +\n              \"flags from log\");\n        }\n      }\n      reader = FSEditLogOp.Reader.create(dataIn, tracker, logVersion);\n      reader.setMaxOpSize(maxOpSize);\n      state = State.OPEN;\n    } finally {\n      if (reader == null) {\n        IOUtils.cleanupWithLogger(LOG, dataIn, tracker, bin, fStream);\n        state = State.CLOSED;\n      }\n    }\n  }\n\n  @Override\n  public long getFirstTxId() {\n    return firstTxId;\n  }","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EditLogFileInputStream.java#L165-L201","documentation":"LogHeaderCorruptException('EOF while reading layout flags from log') from EditLogFileInputStream.setup(): the 4-byte layout version was read successfully (and supports ADD_LAYOUT_FLAGS or comes from a newer layout), but LayoutFlags.read(dataIn) hit EOF. The header was only half written -- version present, layout-flags byte(s) missing -- so the segment is corrupt exactly like a missing header.","triggerScenarios":"A torn header write on segment creation (crash/disk-full after the version int but before layout flags); a truncated copy of a valid segment cut right after the version int; validated during NN startup replay, edits validation, or offlineEditsViewer.","commonSituations":"Same family as other torn edit-log headers: power loss during segment roll, full name device, or interrupted copying of journal files between hosts.","solutions":["Run hdfs namenode -recover and discard/sideline the corrupt segment.","If the segment carried real transactions, restore the journal from a peer: bootstrapStandby (HA) or -importCheckpoint, or replay from the last good fsimage plus surviving segments.","Repair the storage/durability cause so headers cannot be torn again (local reliable disk for name dirs, QJM for shared edits)."],"exampleFix":"# before: 'EOF while reading layout flags from log' on startup\nhdfs namenode -recover\n# after: corrupt half-written segment sidelined; if transactions were lost,\n# bootstrapStandby / -importCheckpoint from a peer's image","handlingStrategy":"try-catch","validationCode":"try (DataInputStream in = new DataInputStream(\n        new BufferedInputStream(Files.newInputStream(editsFile)))) {\n  int v = in.readInt();\n  if (supportsLayoutFlags(v)) LayoutFlags.read(in);  // EOF here == torn header\n}","typeGuard":null,"tryCatchPattern":"catch (EditLogFileInputStream.LogHeaderCorruptException e) {\n  if (e.getMessage().contains(\"layout flags\")) {\n    // torn header (version written, flags missing): segment is corrupt; sideline + fall back to last good image\n  } else { throw e; }\n}","preventionTips":["Same durability hygiene as all torn-write cases: local disks, UPS/fsync, QJM for redundancy.","Validate suspected segments with offlineEditsViewer -r before deciding what to discard.","Restore path readiness: keep an HA peer or recent checkpoint so one torn segment is not data loss."],"tags":["hdfs","edit-log","corruption","layout-flags","namenode-startup"],"backgroundTag":"edit-log-corruption","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}