{"record":{"id":"6b32645622c2a6ac","repo":"apache/seatunnel","slug":"rename-file-failed-will-continue-move-file-but-m","errorCode":null,"errorMessage":"rename file failed, will continue move file, but maybe cause file conflict","messagePattern":"rename file failed, will continue move file, but maybe cause file conflict","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"seatunnel-connectors-v2/connector-clickhouse/src/main/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/sink/file/ClickhouseFileSinkWriter.java","lineNumber":379,"sourceCode":"                    ClickhouseConnectorErrorCode.FILE_NOT_EXISTS,\n                    \"clickhouse local file not exists\");\n        }\n        return Arrays.stream(files)\n                .filter(File::isDirectory)\n                .filter(f -> !\"detached\".equals(f.getName()))\n                .map(\n                        f -> {\n                            File newFile =\n                                    new File(\n                                            f.getParent()\n                                                    + \"/\"\n                                                    + f.getName()\n                                                    + \"_\"\n                                                    + context.getIndexOfSubtask());\n                            if (f.renameTo(newFile)) {\n                                return newFile;\n                            } else {\n                                log.warn(\n                                        \"rename file failed, will continue move file, but maybe cause file conflict\");\n                                return f;\n                            }\n                        })\n                .map(File::getAbsolutePath)\n                .collect(Collectors.toList());\n    }\n\n    private void moveClickhouseLocalFileToServer(Shard shard, List<String> clickhouseLocalFiles) {\n        String hostAddress = shard.getNode().getHost();\n        String user = readerOption.getNodeUser().getOrDefault(hostAddress, \"root\");\n        String password = readerOption.getNodePassword().getOrDefault(hostAddress, null);\n        String keyPath = readerOption.getKeyPath();\n        FileTransfer fileTransfer =\n                FileTransferFactory.createFileTransfer(\n                        this.readerOption.getCopyMethod(), hostAddress, user, password, keyPath);\n        fileTransfer.init();\n        int randomPath = threadLocalRandom.nextInt(shardLocalDataPaths.get(shard).size());","sourceCodeStart":361,"sourceCodeEnd":397,"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#L361-L397","documentation":"When preparing ClickHouse local part files for transfer, ClickhouseFileSinkWriter renames each file to include the subtask index to avoid name conflicts between subtasks. If File.renameTo fails (typically a cross-filesystem move or permission issue), it logs this warning and returns the original file name, which may collide with files from other subtasks.","triggerScenarios":"generateClickhouseLocalFiles calls f.renameTo(newFile) and the OS rename fails — e.g. source and target on different mount points, target file exists, or insufficient write permission on the target directory.","commonSituations":"SeaTunnel tmp directory and ClickHouse local data directory on different filesystems; multiple subtasks sharing a working dir where the target name already exists; container volume mounts with restricted permissions.","solutions":["Configure the ClickHouse local file paths so temp and target directories are on the same filesystem/device.","Ensure the target directory is writable by the SeaTunnel process user and the target filename does not already exist.","Clean up stale part files from previous failed runs to avoid name conflicts."],"exampleFix":"// before\nif (f.renameTo(newFile)) {\n    return newFile;\n} else {\n    log.warn(\"rename file failed, ...\");\n    return f;\n}\n// after (Java 7+ atomic move with fallback)\ntry {\n    Files.move(f.toPath(), newFile.toPath(), StandardCopyOption.REPLACE_EXISTING);\n    return newFile;\n} catch (IOException e) {\n    log.warn(\"rename file failed: {}\", e.getMessage());\n    return f;\n}","handlingStrategy":"fallback","validationCode":"// ensure same filesystem before run\nFile src = ..., dst = ...;\nif (!src.toPath().getFileSystem(env).equals(dst.toPath().getFileSystem(env))) {\n    throw new IllegalStateException(\"source and target must share a filesystem\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Place temp and ClickHouse local dirs on the same mount/device","Pre-clean stale part files from previous runs","Verify write permissions for the SeaTunnel process user on target dirs"],"tags":["clickhouse","file-io","filesystem","conflict"],"backgroundTag":"file-rename-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}