{"record":{"id":"b33706780261103f","repo":"apache/hadoop","slug":"op-opcodebyte-has-size-oplength-but-the-minim","errorCode":null,"errorMessage":"Op {opCodeByte} has size {opLength}, but the minimum op size is {MIN_OP_LENGTH}","messagePattern":"Op (.+?) has size (.+?), but the minimum op size is (.+?)","errorType":"exception","errorClass":"java.io.IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogOp.java","lineNumber":5252,"sourceCode":"      } catch (EOFException eof) {\n        // EOF at an opcode boundary is expected.\n        return HdfsServerConstants.INVALID_TXID;\n      }\n      if (opCodeByte == FSEditLogOpCodes.OP_INVALID.getOpCode()) {\n        verifyTerminator();\n        return HdfsServerConstants.INVALID_TXID;\n      }\n      // Here, we verify that the Op size makes sense and that the\n      // data matches its checksum before attempting to construct an Op.\n      // This is important because otherwise we may encounter an\n      // OutOfMemoryException which could bring down the NameNode or\n      // JournalNode when reading garbage data.\n      int opLength =  in.readInt() + OP_ID_LENGTH + CHECKSUM_LENGTH;\n      if (opLength > maxOpSize) {\n        throw new IOException(\"Op \" + (int)opCodeByte + \" has size \" +\n            opLength + \", but maxOpSize = \" + maxOpSize);\n      } else  if (opLength < MIN_OP_LENGTH) {\n        throw new IOException(\"Op \" + (int)opCodeByte + \" has size \" +\n            opLength + \", but the minimum op size is \" + MIN_OP_LENGTH);\n      }\n      long txid = in.readLong();\n      // Verify checksum\n      in.reset();\n      in.mark(maxOpSize);\n      checksum.reset();\n      for (int rem = opLength - CHECKSUM_LENGTH; rem > 0;) {\n        int toRead = Math.min(temp.length, rem);\n        IOUtils.readFully(in, temp, 0, toRead);\n        checksum.update(temp, 0, toRead);\n        rem -= toRead;\n      }\n      int expectedChecksum = in.readInt();\n      int calculatedChecksum = (int)checksum.getValue();\n      if (expectedChecksum != calculatedChecksum) {\n        throw new ChecksumException(\n            \"Transaction is corrupt. Calculated checksum is \" +","sourceCodeStart":5234,"sourceCodeEnd":5270,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogOp.java#L5234-L5270","documentation":"Companion minimum-size check in decodeOpFrame(): a length-prefixed record needs at least MIN_OP_LENGTH = 17 bytes (1 opcode + 4 length + 8 txid + 0-byte body + 4 checksum, FSEditLogOp.java:5168). An opLength below 17 means the length field itself is corrupt or the segment is truncated mid-header, so the reader refuses to decode.","triggerScenarios":"The segment ends (truncation) inside a record header so the length int is partial; the length int is corrupt to a small/negative value; the stream is misaligned after earlier damage.","commonSituations":"Truncated tails from crash or disk-full; bit rot on journal storage; misparsed preceding record shifting offsets.","solutions":["Run 'hdfs namenode -recover' to skip the damaged tail and finish startup, then checkpoint","Verify where truncation begins using 'hdfs offlineEditsViewer'","Fetch an intact copy of the segment from healthy journals (QJM) or fall back to the last fsimage"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"hdfs offlineEditsViewer -i <edits segment> -o /dev/null   # detects truncated/corrupt record headers pre-start","typeGuard":null,"tryCatchPattern":"try {\n  reader.readOp();\n} catch (IOException e) {\n  if (e.getMessage().contains(\"minimum op size\")) {\n    // truncated header or corrupt length field: recover-skip or restore clean copy\n  } else { throw e; }\n}","preventionTips":["Guard journal disks against fills; truncation happens at the tail","Validate segments after crashes before restart","Keep quorum journal copies so truncation never leaves zero good copies"],"tags":["hdfs","edit-log","corruption","truncation","limits"],"backgroundTag":"truncated-message","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}