{"record":{"id":"1b64630eb931417b","repo":"apache/seatunnel","slug":"unable-to-delete-directory-localfiledir","errorCode":null,"errorMessage":"Unable to delete directory \" + localFileDir","messagePattern":"Unable to delete directory \" \\+ localFileDir","errorType":"exception","errorClass":"ClickhouseConnectorException","httpStatus":null,"severity":"warning","filePath":"seatunnel-connectors-v2/connector-clickhouse/src/main/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/sink/file/ClickhouseFileSinkWriter.java","lineNumber":414,"sourceCode":"        fileTransfer.init();\n        int randomPath = threadLocalRandom.nextInt(shardLocalDataPaths.get(shard).size());\n        fileTransfer.transferAndChown(\n                clickhouseLocalFiles, shardLocalDataPaths.get(shard).get(randomPath) + \"detached/\");\n        fileTransfer.close();\n    }\n\n    private void clearLocalFileDirectory(List<String> clickhouseLocalFiles) {\n        String clickhouseLocalFile = clickhouseLocalFiles.get(0);\n        String localFileDir =\n                clickhouseLocalFile.substring(\n                        0, readerOption.getFileTempPath().length() + UUID_LENGTH + 1);\n        try {\n            File file = new File(localFileDir);\n            if (file.exists()) {\n                FileUtils.deleteDirectory(file);\n            }\n        } catch (IOException e) {\n            throw new ClickhouseConnectorException(\n                    ClickhouseConnectorErrorCode.DELETE_DIRECTORY_FIELD,\n                    \"Unable to delete directory \" + localFileDir,\n                    e);\n        }\n    }\n\n    private String adjustClickhouseDDL() {\n        String createTableDDL =\n                clickhouseTable\n                        .getCreateTableDDL()\n                        .replace(clickhouseTable.getDatabase() + \".\", \"\")\n                        .replaceAll(\"`\", \"\");\n        if (createTableDDL.contains(CLICKHOUSE_SETTINGS_KEY)) {\n            List<String> filters =\n                    Arrays.stream(CLICKHOUSE_DDL_SETTING_FILTER.split(\",\"))\n                            .collect(Collectors.toList());\n            int p = createTableDDL.indexOf(CLICKHOUSE_SETTINGS_KEY);\n            String filteredSetting =","sourceCodeStart":396,"sourceCodeEnd":432,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-clickhouse/src/main/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/sink/file/ClickhouseFileSinkWriter.java#L396-L432","documentation":"clearLocalFileDirectory removes the temporary local file directory with commons-io FileUtils.deleteDirectory after flushing. If an IOException occurs during deletion, it wraps it in a ClickhouseConnectorException with DELETE_DIRECTORY_FIELD and the message \"Unable to delete directory <dir>\".","triggerScenarios":"prepareCommit's finally-block cleanup when the OS refuses to delete the directory — files locked by another process, permission denied on files inside the directory, or directory still in use.","commonSituations":"A leftover clickhouse-local process still holds file handles in the directory; the worker user lacks write permission on parent dir or contained files; NFS/network filesystem mount issues.","solutions":["Check for running clickhouse-local processes holding files open in the directory and kill them","Grant the worker user write permission on the directory and its contents","Manually delete the leftover directory if it blocks subsequent runs","Avoid putting localFileDir on flaky network filesystems"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    // flush\n} catch (ClickhouseConnectorException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Unable to delete directory\")) {\n        // schedule manual cleanup of localFileDir; check for file locks\n    }\n}","preventionTips":["Ensure no lingering clickhouse-local processes hold handles in the directory","Give the worker write permission on localFileDir and its parent","Use local disk instead of NFS for localFileDir"],"tags":["filesystem","cleanup","io"],"backgroundTag":"file-write-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}