{"record":{"id":"1f1a2089b11f5f79","repo":"apache/hadoop","slug":"no-header-found-in-log","errorCode":null,"errorMessage":"No header found in log","messagePattern":"No header found in 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":164,"sourceCode":"    this.lastTxId = lastTxId;\n    this.isInProgress = isInProgress;\n    this.maxOpSize = DFSConfigKeys.DFS_NAMENODE_MAX_OP_SIZE_DEFAULT;\n  }\n\n  private void init(boolean verifyLayoutVersion)\n      throws LogHeaderCorruptException, IOException {\n    Preconditions.checkState(state == State.UNINIT);\n    BufferedInputStream bin = null;\n    InputStream fStream = null;\n    try {\n      fStream = log.getInputStream();\n      bin = new BufferedInputStream(fStream);\n      tracker = new FSEditLogLoader.PositionTrackingInputStream(bin);\n      dataIn = new DataInputStream(tracker);\n      try {\n        logVersion = readLogVersion(dataIn, verifyLayoutVersion);\n      } catch (EOFException eofe) {\n        throw new LogHeaderCorruptException(\"No header found in log\");\n      }\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) {","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/EditLogFileInputStream.java#L146-L182","documentation":"LogHeaderCorruptException('No header found in log') from EditLogFileInputStream.setup(): while opening an edit-log segment, the read of the layout-version header hit EOF before any bytes were consumed, meaning the segment file is zero-length (or truncated before the 4-byte version int). The NameNode treats such segments as corrupt; genuinely empty in-progress segments may be sidelined, but an unexpected empty segment aborts journal replay or validation.","triggerScenarios":"NameNode startup replay (FSEditLogLoader) or edit-log validation (EditLogFileInputStream.validateLog / offlineEditsViewer) opens an edits_* file that contains 0 bytes: a segment file created but never flushed (crash between open and header write), or a copy of live edits truncated by tooling.","commonSituations":"Power loss or disk-full at the moment a new edit segment was being rolled; name-dir on unreliable storage producing zero-length files; rsync/scp of a live edits file catching it mid-creation; monitoring scripts touching files in name/current.","solutions":["Restart with recovery: hdfs namenode -recover and choose to discard/sideline the corrupt segment (safe if it truly held no transactions).","If the file is edits_in_progress_* with no valid header, move it aside (it has no transactions) and restart from the previous fsimage plus earlier segments.","If real transactions are lost, restore the name dir from a checkpoint: bootstrapStandby from an HA peer, or -importCheckpoint from a SecondaryNameNode/backup copy.","Fix the durability root cause: keep dfs.namenode.name.dir on reliable local storage, check dmesg/RAID/fill levels, and stop copying live edits files."],"exampleFix":"# before: NN startup fails with 'No header found in log' on edits_in_progress_0000000000012345\nhdfs namenode -recover    # choose to discard the empty/corrupt segment\n# after: NN starts, empty segment is sidelined, replay continues from prior segment","handlingStrategy":"try-catch","validationCode":"// peek the 4-byte layout version before handing a segment to any loader\ntry (DataInputStream in = new DataInputStream(\n        new BufferedInputStream(Files.newInputStream(editsFile)))) {\n  int v = in.readInt();   // EOFException here == 'No header found' case\n  // v == -1 -> empty preallocated edits_in_progress; see error 2585\n}","typeGuard":"static boolean isCorruptLogHeader(IOException e) {\n  return e instanceof EditLogFileInputStream.LogHeaderCorruptException;\n}","tryCatchPattern":"try {\n  EditLogFileInputStream in = new EditLogFileInputStream(file);\n  in.refresh(false);\n} catch (EditLogFileInputStream.LogHeaderCorruptException e) {\n  // segment holds no readable transactions: sideline it (rename aside) and continue from prior segment\n}","preventionTips":["Keep dfs.namenode.name.dir on reliable local storage; never NFS or network mounts that can truncate writes.","Use HA with QJM so a torn local edit segment never blocks journal continuity.","Never copy live edits_* files; snapshot the name dir only while the NN is down.","Run hdfs namenode -recover rather than hand-deleting when headers are corrupt."],"tags":["hdfs","edit-log","corruption","namenode-startup"],"backgroundTag":"edit-log-corruption","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}