{"record":{"id":"5b93130ba547865a","repo":"apache/hadoop","slug":"the-layout-version-supports-inodeid-but-gave-bo","errorCode":null,"errorMessage":"The layout version {} supports inodeId but gave bogus inodeId","messagePattern":"The layout version (.+?) supports inodeId but gave bogus inodeId","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java","lineNumber":371,"sourceCode":"        dumpOpCounts(opCounts);\n        FSImage.LOG.debug(\"maxTxnsToRead = \" + maxTxnsToRead\n            + \" actual edits read = \" + numEdits);\n      }\n      assert numEdits <= maxTxnsToRead || numEdits == 1 :\n        \"should read at least one txn, but not more than the configured max\";\n    }\n    return numEdits;\n  }\n  \n  // allocate and update last allocated inode id\n  private long getAndUpdateLastInodeId(long inodeIdFromOp, int logVersion,\n      long lastInodeId) throws IOException {\n    long inodeId = inodeIdFromOp;\n\n    if (inodeId == HdfsConstants.GRANDFATHER_INODE_ID) {\n      if (NameNodeLayoutVersion.supports(\n          LayoutVersion.Feature.ADD_INODE_ID, logVersion)) {\n        throw new IOException(\"The layout version \" + logVersion\n            + \" supports inodeId but gave bogus inodeId\");\n      }\n      inodeId = fsNamesys.dir.allocateNewInodeId();\n    } else {\n      // need to reset lastInodeId. fsnamesys gets lastInodeId firstly from\n      // fsimage but editlog captures more recent inodeId allocations\n      if (inodeId > lastInodeId) {\n        fsNamesys.dir.resetLastInodeId(inodeId);\n      }\n    }\n    return inodeId;\n  }\n\n  @SuppressWarnings(\"deprecation\")\n  private long applyEditLogOp(FSEditLogOp op, FSDirectory fsDir,\n      StartupOption startOpt, int logVersion, long lastInodeId) throws IOException {\n    long inodeId = HdfsConstants.GRANDFATHER_INODE_ID;\n    if (LOG.isTraceEnabled()) {","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogLoader.java#L353-L389","documentation":"getAndUpdateLastInodeId validates inode-creating ops: the log's layout version includes ADD_INODE_ID, so inode ids must be serialized, yet the op carried the GRANDFATHER_INODE_ID (0) sentinel reserved for logs too old to contain ids. That combination is self-inconsistent and replay throws IOException. It points at corruption or a faulty log writer, not at a normal upgrade path.","triggerScenarios":"Bit-level corruption zeroing the inodeId field of an OP_ADD or similar record; edit logs produced by a patched or buggy build that wrote 0 instead of an allocated id; hand-modified segment files.","commonSituations":"Disk errors or bad segment transfers; replaying logs from experimental in-house Hadoop builds. Rare on stock releases.","solutions":["Treat the segment as corrupt: confirm with the OfflineEditsViewer ('hdfs oev -i <segment> -o /tmp/check.xml -p xml')","Recover with 'hdfs namenode -recover' and skip the bad section, or restore a matching fsimage plus edits from backup","If the logs come from an internal build, fix that writer to allocate and record a real inode id"],"exampleFix":"# before: replay aborts with 'gave bogus inodeId'\nhdfs --daemon start namenode\n\n# after: prove which segment is bad, then skip it\nhdfs oev -i edits_0000000000000001234-0000000000000001400 -o /tmp/check.xml -p xml\nhdfs namenode -recover","handlingStrategy":"try-catch","validationCode":"hdfs oev -i <segment> -o /tmp/check.xml -p xml   # full parse validates every record's fields","typeGuard":null,"tryCatchPattern":"try {\n  loader.loadFSEdits(storage, 0);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"bogus inodeId\")) {\n    // structurally corrupt record: restart with 'hdfs namenode -recover'\n    // or restore a consistent fsimage+edits pair from backup\n  }\n  throw e;\n}","preventionTips":["Do not hand-edit or regenerate edit log files","Verify checksums when archiving or copying segments between hosts","Replace disks that report read errors instead of trusting their data"],"tags":["hdfs","namenode","edit-log","inode-id","layout-version","corruption","replay"],"backgroundTag":"edit-log-corruption","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}