{"record":{"id":"8b9aaef6ee9fe4cb","repo":"apache/hadoop","slug":"failed-to-mkdir-on","errorCode":null,"errorMessage":"Failed to mkdir on {}","messagePattern":"Failed to mkdir on (.+?)","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":400,"sourceCode":"      protected boolean removeEldestEntry(Map.Entry<Long, String> entry) {\n        return super.size() > CAPACITY;\n      }\n    }\n\n    /** Map the child inode to the parent directory inode. */\n    private LevelDBStore dirChildMap = null;\n    /** Directory entry map */\n    private LevelDBStore dirMap = null;\n    private DirPathCache dirPathCache = new DirPathCache();\n\n    LevelDBMetadataMap(String baseDir) throws IOException {\n      File dbDir = new File(baseDir);\n      if (dbDir.exists()) {\n        throw new IOException(\"Folder \" + dbDir + \" already exists! Delete \" +\n            \"manually or provide another (not existing) directory!\");\n      }\n      if (!dbDir.mkdirs()) {\n        throw new IOException(\"Failed to mkdir on \" + dbDir);\n      }\n      try {\n        dirChildMap = new LevelDBStore(new File(dbDir, \"dirChildMap\"));\n        dirMap = new LevelDBStore(new File(dbDir, \"dirMap\"));\n      } catch (IOException e) {\n        LOG.error(\"Failed to open LevelDBs\", e);\n        IOUtils.cleanupWithLogger(null, this);\n      }\n    }\n\n    @Override\n    public void close() throws IOException {\n      IOUtils.cleanupWithLogger(null, dirChildMap, dirMap);\n      dirChildMap = null;\n      dirMap = null;\n    }\n\n    private static byte[] toBytes(long value) {","sourceCodeStart":382,"sourceCodeEnd":418,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageTextWriter.java#L382-L418","documentation":"Same LevelDB temp-dir setup, next failure mode: File.mkdirs() on the -t path returned false, so the directory could not be created at all. This is an OS-level problem — a missing or unwritable parent, a regular file shadowing a path component, a read-only filesystem, or an SELinux/ACL denial.","triggerScenarios":"Pointing -t at a path whose parent does not exist or is not writable by the oiv user; a path component is a file (e.g. -t /tmp/x/y where /tmp/x is a regular file); read-only or SELinux-confined mount.","commonSituations":"Running oiv as an unprivileged user against system paths; NFS or read-only mounts; typos in the temp path.","solutions":["Create and probe the parent as the same user: `mkdir -p \"$(dirname <dir>)\" && touch <dir>.probe && rm <dir>.probe`","Move -t to a location the running user owns (home directory, /tmp/$USER)","Check each path component with `ls -l` for a file masquerading as a directory, and `mount` for a read-only filesystem"],"exampleFix":"# before: parent not writable\nhdfs oiv -p delimited -i fsimage -o out.csv -t /var/lib/hadoop/oivtmp\n# IOException: Failed to mkdir on /var/lib/hadoop/oivtmp\n\n# after: writable parent, created first\nmkdir -p ~/oiv-parent\nhdfs oiv -p delimited -i fsimage -o out.csv -t ~/oiv-parent/run1","handlingStrategy":"validation","validationCode":"File dbDir = new File(tempPath);\nFile parent = dbDir.getAbsoluteFile().getParentFile();\nif (dbDir.exists()) {\n  throw new IllegalStateException(\"temp dir \" + dbDir + \" already exists\");\n}\nif (parent == null || !parent.isDirectory() || !parent.canWrite()) {\n  throw new IllegalStateException(\n      \"cannot create \" + dbDir + \": parent missing, not a directory, or not writable\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create the parent directory yourself (mkdir -p) before running oiv with -t","Point -t at storage the oiv user owns (home dir, /tmp/$USER)","Watch for regular files shadowing path components and read-only mounts"],"tags":["hdfs","offline-image-viewer","filesystem","permissions"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}