{"record":{"id":"147397ad2616d221","repo":"apache/hadoop","slug":"incorrect-data-format-mkdir-operation","errorCode":null,"errorMessage":"Incorrect data format. Mkdir operation.","messagePattern":"Incorrect data format\\. Mkdir operation\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogOp.java","lineNumber":1696,"sourceCode":"      FSImageSerialization.writeLong(timestamp, out); // atime, unused at this\n      permissions.write(out);\n      AclEditLogUtil.write(aclEntries, out);\n      XAttrEditLogProto.Builder b = XAttrEditLogProto.newBuilder();\n      b.addAllXAttrs(PBHelperClient.convertXAttrProto(xAttrs));\n      b.build().writeDelimitedTo(out);\n    }\n    \n    @Override\n    void readFields(DataInputStream in, int logVersion) throws IOException {\n      if (!NameNodeLayoutVersion.supports(\n          LayoutVersion.Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {\n        this.length = in.readInt();\n      }\n      if (-17 < logVersion && length != 2 ||\n          logVersion <= -17 && length != 3\n          && !NameNodeLayoutVersion.supports(\n              LayoutVersion.Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {\n        throw new IOException(\"Incorrect data format. Mkdir operation.\");\n      }\n      if (NameNodeLayoutVersion.supports(\n          LayoutVersion.Feature.ADD_INODE_ID, logVersion)) {\n        this.inodeId = FSImageSerialization.readLong(in);\n      } else {\n        // This id should be updated when this editLogOp is applied\n        this.inodeId = HdfsConstants.GRANDFATHER_INODE_ID;\n      }\n      this.path = FSImageSerialization.readString(in);\n      if (NameNodeLayoutVersion.supports(\n          LayoutVersion.Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {\n        this.timestamp = FSImageSerialization.readLong(in);\n      } else {\n        this.timestamp = readLong(in);\n      }\n\n      // The disk format stores atimes for directories as well.\n      // However, currently this is not being updated/used because of","sourceCodeStart":1678,"sourceCodeEnd":1714,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogOp.java#L1678-L1714","documentation":"MkdirOp.readFields() enforces a version-dependent field count on legacy records: for logVersion > -17 the length word must be 2, and for logVersion <= -17 (but still without EDITLOG_OP_OPTIMIZATION) it must be 3, because layout -17 added a field to mkdir records. Failing either check means the record is corrupt or is being interpreted with the wrong layout version.","triggerScenarios":"A corrupt length word in an old mkdir record; a legacy segment whose layout-version header disagrees with the actual field layout written; misalignment after earlier damage.","commonSituations":"Edits spanning the Hadoop 0.20-era layout -17 boundary; archives of very old clusters replayed by newer tooling; disk corruption of legacy segments.","solutions":["Run 'hdfs namenode -recover' to skip the record and continue","If replaying an archived old cluster, read it with a Hadoop release matching the layout version that wrote it, checkpoint, then upgrade","Locate the failing txid with 'hdfs offlineEditsViewer' and restore undamaged copies"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"hdfs offlineEditsViewer -i <legacy edits segment> -o /dev/null   # use a release matching the segment's layout version","typeGuard":null,"tryCatchPattern":"try {\n  reader.readOp();\n} catch (IOException e) {\n  // mkdir field count wrong for the declared layout version:\n  // re-read the segment with the matching Hadoop release, then checkpoint and upgrade\n}","preventionTips":["When replaying archives from pre-0.20 clusters, use a period-correct release first and checkpoint","Never hand-edit layout version headers in stored segments","Keep the original, unmodified name dir until the upgrade checkpoint is verified"],"tags":["hdfs","edit-log","corruption","mkdir","legacy-format","layout-version"],"backgroundTag":"edit-log-corruption","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}