apache/hadoop · error · IOException
Folder {} already exists! Delete manually or provide another
Error message
Folder {} already exists! Delete manually or provide another (not existing) directory! What it means
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.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/PBImageTextWriter.java:396
super(CAPACITY);
}
@Override
protected boolean removeEldestEntry(Map.Entry<Long, String> entry) {
return super.size() > CAPACITY;
}
}
/** Map the child inode to the parent directory inode. */
private LevelDBStore dirChildMap = null;
/** Directory entry map */
private LevelDBStore dirMap = null;
private DirPathCache dirPathCache = new DirPathCache();
LevelDBMetadataMap(String baseDir) throws IOException {
File dbDir = new File(baseDir);
if (dbDir.exists()) {
throw new IOException("Folder " + dbDir + " already exists! Delete " +
"manually or provide another (not existing) directory!");
}
if (!dbDir.mkdirs()) {
throw new IOException("Failed to mkdir on " + dbDir);
}
try {
dirChildMap = new LevelDBStore(new File(dbDir, "dirChildMap"));
dirMap = new LevelDBStore(new File(dbDir, "dirMap"));
} catch (IOException e) {
LOG.error("Failed to open LevelDBs", e);
IOUtils.cleanupWithLogger(null, this);
}
}
@Override
public void close() throws IOException {
IOUtils.cleanupWithLogger(null, dirChildMap, dirMap);
dirChildMap = null;View on GitHub (pinned to 2add963021)
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)
Example fix
# before: fixed temp dir fails on the second run hdfs oiv -p delimited -i fsimage -o out.csv -t /tmp/oivtmp # IOException: Folder /tmp/oivtmp already exists! # after: fresh dir every run rm -rf /tmp/oivtmp hdfs oiv -p delimited -i fsimage -o out.csv -t "$(mktemp -d)"
Defensive patterns
Strategy: validation
Validate before calling
// before starting oiv with -t
Path tmp = Paths.get(tempPath);
if (Files.exists(tmp)) {
throw new IllegalStateException(
"temp dir " + tmp + " already exists; delete it or pick a fresh path");
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Cron jobs or scripts with hardcoded -t paths; reruns after a failure; leftover directories under /tmp.
Related errors
- bytes array length error. Actual length is {}
- InMemoryAliasMap location is null
- Unable to create aliasmap snapshot directory {newLevelDBDir}
- Cannot remove current alias map: ${aliasMapFile}
- Param op must be specified.
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/e8f80997afda0659.
Report an issue: GitHub.