{"record":{"id":"2105eccc413778c2","repo":"apache/dolphinscheduler","slug":"directory-already-exists-directoryabsolutepath-2105ec","errorCode":null,"errorMessage":"Directory already exists: ${directoryAbsolutePath}","messagePattern":"Directory already exists: (.+?)","errorType":"exception","errorClass":"FileAlreadyExistsException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-storage-plugin/dolphinscheduler-storage-hdfs/src/main/java/org/apache/dolphinscheduler/plugin/storage/hdfs/HdfsStorageOperator.java","lineNumber":166,"sourceCode":"    @Override\n    public List<String> fetchFileContent(String hdfsFilePath, int skipLineNums, int limit) {\n        try (\n                FSDataInputStream in = fs.open(new Path(hdfsFilePath));\n                InputStreamReader inputStreamReader = new InputStreamReader(in, StandardCharsets.UTF_8);\n                BufferedReader br = new BufferedReader(inputStreamReader)) {\n            return br.lines()\n                    .skip(skipLineNums)\n                    .limit(limit)\n                    .collect(Collectors.toList());\n        }\n    }\n\n    @Override\n    @SneakyThrows\n    public void createStorageDir(String directoryAbsolutePath) {\n        Path path = new Path(directoryAbsolutePath);\n        if (fs.exists(path)) {\n            throw new FileAlreadyExistsException(\"Directory already exists: \" + directoryAbsolutePath);\n        }\n        fs.mkdirs(new Path(directoryAbsolutePath));\n    }\n\n    @SneakyThrows\n    @Override\n    public void download(String srcHdfsFilePath, String dstFile, boolean overwrite) {\n        Path srcPath = new Path(srcHdfsFilePath);\n        File dstPath = new File(dstFile);\n\n        if (dstPath.exists()) {\n            if (dstPath.isFile()) {\n                if (overwrite) {\n                    Files.delete(dstPath.toPath());\n                }\n            } else {\n                log.error(\"destination file must be a file\");\n            }","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-storage-plugin/dolphinscheduler-storage-hdfs/src/main/java/org/apache/dolphinscheduler/plugin/storage/hdfs/HdfsStorageOperator.java#L148-L184","documentation":"HdfsStorageOperator.createStorageDir creates a directory on HDFS via fs.mkdirs. If the HDFS path already exists it throws FileAlreadyExistsException instead of silently succeeding, so callers can detect the collision.","triggerScenarios":"Calling createStorageDir(directoryAbsolutePath) when fs.exists(new Path(directoryAbsolutePath)) is true — a previous mkdir, a resource file already at that path, or a rerun of the same workflow.","commonSituations":"Re-running deployments that create the same resource directory; the path being occupied by a file rather than a directory; shared tenant paths reused across workflows.","solutions":["Check fs.exists / operator.exists first and skip creation if present","Delete the existing path (hdfs dfs -rm -r) if overwrite is safe, then retry","Use a unique path per execution (workflow instance id, timestamp)"],"exampleFix":"// before\nhdfs.createStorageDir(uploadPath);\n// after\nif (!hdfs.exists(uploadPath)) {\n    hdfs.createStorageDir(uploadPath);\n}","handlingStrategy":"validation","validationCode":"if (hdfs.exists(hdfsPath)) { /* skip or choose a new path */ }","typeGuard":null,"tryCatchPattern":"try {\n    hdfs.createStorageDir(path);\n} catch (FileAlreadyExistsException e) {\n    log.info(\"HDFS directory exists, reusing: {}\", path);\n}","preventionTips":["Check exists() before mkdirs-style calls","Use unique per-execution paths for workflow outputs","Note the path may be occupied by a file, not just a directory"],"tags":["hdfs","storage","duplicate-resource"],"backgroundTag":"file-already-exists","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}