{"record":{"id":"e66ba72d5fd50b7e","repo":"apache/hadoop","slug":"the-length-of-the-feature-flag-section-was-negativ","errorCode":null,"errorMessage":"The length of the feature flag section was negative at {} bytes.","messagePattern":"The length of the feature flag section was negative at (.+?) bytes\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"critical","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/LayoutFlags.java","lineNumber":45,"sourceCode":" * LayoutFlags represent features which the FSImage and edit logs can either\n * support or not, independently of layout version.\n * \n * Note: all flags starting with 'test' are reserved for unit test purposes.\n */\n@InterfaceAudience.Private\npublic class LayoutFlags {\n\n  /**\n   * Read next int from given input stream. If the value is not 0 (unsupported\n   * feature flags), throw appropriate IOException.\n   *\n   * @param in            The stream to read from.\n   * @throws IOException  If next byte read from given stream is not 0.\n   */\n  public static void read(DataInputStream in) throws IOException {\n    int length = in.readInt();\n    if (length < 0) {\n      throw new IOException(\"The length of the feature flag section \" +\n          \"was negative at \" + length + \" bytes.\");\n    } else if (length > 0) {\n      throw new IOException(\"Found feature flags which we can't handle. \" +\n          \"Please upgrade your software.\");\n    }\n  }\n\n  private LayoutFlags() {\n  }\n\n  public static void write(DataOutputStream out) throws IOException {\n    out.writeInt(0);\n  }\n}\n","sourceCodeStart":27,"sourceCodeEnd":60,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/LayoutFlags.java#L27-L60","documentation":"LayoutFlags.read consumes an int in the fsimage/segment header reserved for future on-disk feature flags; today only 0 is valid. A negative value is meaningless as a length and signals that the stream is being read from the wrong position or the file is damaged - effectively an image-corruption detector.","triggerScenarios":"A NameNode/BackupNode reading a truncated or byte-corrupted fsimage; feeding a non-image file (edit segment, .md5 sidecar, empty file) into an image loader; reading a header at the wrong offset after prior corruption.","commonSituations":"Checkpoint interrupted by crash/power loss leaving a partial fsimage; failing disks flipping bytes; image files copied in text mode or truncated during transfer between nodes.","solutions":["Treat it as corruption: restore the previous good fsimage from the checkpoint/backup directories (image + matching .md5)","Verify integrity: compare fsimage_XXXX against its fsimage_XXXX.md5 companion before loading","If the file was copied, recopy in binary mode; check disk and filesystem health (dmesg, smartctl) on the NameNode"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Before loading, verify the image against its md5 sidecar\nimport org.apache.hadoop.hdfs.server.namenode.FSImageFormatProtobuf; // helper APIs vary\n// simple shell-level guard:\n//   cd $dfs.namenode.name.dir/current && md5sum -c <(sed 's/ /  /' fsimage_000*.md5)\n// a failed checksum means the image is corrupt - restore a checkpoint instead of loading","typeGuard":null,"tryCatchPattern":"try {\n  namenode.loadFsImage(); // or BackupNode/secondary ingestion\n} catch (IOException e) {\n  if (e.getMessage().contains(\"feature flag section\")) {\n    // corruption / wrong file: restore previous fsimage from backup dirs; do NOT retry the same file\n  } else {\n    throw e;\n  }\n}","preventionTips":["Keep at least the last two checkpoints on separate disks and monitor checkpoint success (NNGanimator/Standby logs)","Validate fsimage_XXXX against fsimage_XXXX.md5 after every copy between nodes","React to disk errors in name dirs immediately - most image corruption starts as a failing disk"],"tags":["hdfs","namenode","fsimage","corruption","metadata","checkpoint"],"backgroundTag":"metadata-corruption","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}