{"record":{"id":"aae9a4fdbe11f625","repo":"apache/hadoop","slug":"bytes-array-length-error-actual-length-is","errorCode":null,"errorMessage":"bytes array length error. Actual length is {}","messagePattern":"bytes array length error\\. Actual length is (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageTextWriter.java","lineNumber":455,"sourceCode":"      dirChildMap.put(toBytes(childId), toBytes(parentId));\n    }\n\n    @Override\n    public void putDir(INode dir) throws IOException {\n      Preconditions.checkArgument(dir.hasDirectory(),\n          \"INode %s (%s) is not a directory.\", dir.getId(), dir.getName());\n      dirMap.put(toBytes(dir.getId()), toBytes(dir.getName().toStringUtf8()));\n    }\n\n    private long getFromDirChildMap(long inode) throws IOException {\n      byte[] bytes = dirChildMap.get(toBytes(inode));\n      if (bytes == null) {\n        // The inode is an INodeReference, which is generated from snapshot.\n        // For delimited oiv tool, no need to print out metadata in snapshots.\n        throw PBImageTextWriter.createIgnoredSnapshotException(inode);\n      }\n      if (bytes.length != 8) {\n        throw new IOException(\n            \"bytes array length error. Actual length is \" + bytes.length);\n      }\n      return toLong(bytes);\n    }\n\n    @Override\n    public String getParentPath(long inode) throws IOException {\n      if (inode == INodeId.ROOT_INODE_ID) {\n        return \"/\";\n      }\n      long parent = getFromDirChildMap(inode);\n      byte[] bytes = dirMap.get(toBytes(parent));\n      synchronized (this) {\n        if (!dirPathCache.containsKey(parent)) {\n          if (parent != INodeId.ROOT_INODE_ID && bytes == null) {\n            // The parent is an INodeReference, which is generated from snapshot.\n            // For delimited oiv tool, no need to print out metadata in snapshots.\n            throw PBImageTextWriter.createIgnoredSnapshotException(inode);","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageTextWriter.java#L437-L473","documentation":"In LevelDB mode, the value stored for each directory child in dirChildMap is the 8-byte parent inode id; this decode found a different length. The map is built in-process from the fsimage moments earlier, so a wrong length means the LevelDB store itself got corrupted mid-run (failing disk, another process touching the temp dir) — it is not caused by oiv arguments or the fsimage content.","triggerScenarios":"Corruption of the LevelDB files under the -t directory while oiv is running: failing disk, another process writing into the live temp dir, or filesystem-level data damage on local or NFS-backed temp storage.","commonSituations":"Flaky local/NFS temp storage; operators clearing or copying files inside the live temp directory; very large images where long run times increase exposure.","solutions":["Rerun with a brand-new -t directory (delete the old one first)","Rerun without -t to keep the metadata map in memory; this isolates the temp storage as the culprit","If it reproduces deterministically with a fresh dir and the same fsimage, verify the fsimage md5 and file a HADOOP JIRA for PBImageTextWriter"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  // oiv run with -t\n} catch (IOException e) {\n  if (e.getMessage().contains(\"bytes array length error\")) {\n    // internal LevelDB corruption: wipe temp dir and retry once, in memory if possible\n    FileUtils.deleteQuietly(new File(tempPath));\n    // rerun oiv without -t (or with a fresh -t)\n  } else {\n    throw e;\n  }\n}","preventionTips":["Use a fresh -t directory for every run and delete it afterwards","Put the temp dir on healthy local disk, not NFS or a flaky mount","Do not touch files inside the live -t directory while oiv is running"],"tags":["hdfs","offline-image-viewer","leveldb","data-corruption"],"backgroundTag":"data-corruption-detected","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}