{"record":{"id":"e8f80997afda0659","repo":"apache/hadoop","slug":"folder-already-exists-delete-manually-or-provi","errorCode":null,"errorMessage":"Folder {} already exists! Delete manually or provide another (not existing) directory!","messagePattern":"Folder (.+?) already exists! Delete manually or provide another \\(not existing\\) directory!","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":396,"sourceCode":"        super(CAPACITY);\n      }\n\n      @Override\n      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;","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageTextWriter.java#L378-L414","documentation":"When `hdfs oiv` runs a text processor with `-t/--temp <dir>`, PBImageTextWriter caches parent/child metadata in LevelDB databases under that directory. The LevelDBMetadataMap constructor demands a directory that does not yet exist, so no stale LevelDB data can leak into this run; if the path already exists it refuses immediately.","triggerScenarios":"Running `hdfs oiv -p delimited -t /path/dir` (or DetectCorruption with -t) when that directory already exists — typically the second run of a script with a fixed temp path, or a leftover from a crashed previous run.","commonSituations":"Cron jobs or scripts with hardcoded -t paths; reruns after a failure; leftover directories under /tmp.","solutions":["Delete the leftover directory and rerun: `rm -rf <tempdir>`","Use a unique path per run, e.g. `-t \"$(mktemp -d)\"` or -t /tmp/oiv-$(date +%s)","Drop -t entirely for images whose metadata fits in memory (the default keeps it in-heap)"],"exampleFix":"# before: fixed temp dir fails on the second run\nhdfs oiv -p delimited -i fsimage -o out.csv -t /tmp/oivtmp\n# IOException: Folder /tmp/oivtmp already exists!\n\n# after: fresh dir every run\nrm -rf /tmp/oivtmp\nhdfs oiv -p delimited -i fsimage -o out.csv -t \"$(mktemp -d)\"","handlingStrategy":"validation","validationCode":"// before starting oiv with -t\nPath tmp = Paths.get(tempPath);\nif (Files.exists(tmp)) {\n  throw new IllegalStateException(\n      \"temp dir \" + tmp + \" already exists; delete it or pick a fresh path\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use a unique -t path per run, e.g. $(mktemp -d) or /tmp/oiv-$(date +%s)","Clean up the temp dir in a trap/finally even when oiv fails","Skip -t for images small enough to keep metadata in memory"],"tags":["hdfs","offline-image-viewer","leveldb","temp-dir"],"backgroundTag":"output-dir-already-exists","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}