You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "yzeng1618 (via GitHub)" <gi...@apache.org> on 2026/01/04 08:24:19 UTC

[PR] [Feature][Connector-File-Hadoop] Support sync_mode=update for HdfsFile source (binary) [seatunnel]

yzeng1618 opened a new pull request, #10268:
URL: https://github.com/apache/seatunnel/pull/10268

   …e source (binary)
   
   <!--
   
   Thank you for contributing to SeaTunnel! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   ## Contribution Checklist
     - Make sure that the pull request corresponds to a [GITHUB issue](https://github.com/apache/seatunnel/issues).
     - Name the pull request in the form "[Feature] [component] Title of the pull request", where *Feature* can be replaced by `Hotfix`, `Bug`, etc.
     - Minor fixes should be named following this pattern: `[hotfix] [docs] Fix typo in README.md doc`.
   -->
   
   ### Purpose of this pull request
   
   Add sync_mode=update to HdfsFile source to only sync new/changed files by comparing source/target (len+mtime or Hadoop getFileChecksum).
   
   - Add sync_mode=update for HdfsFile source (currently only supports file_format_type=binary).
   - Support update_strategy=distcp (distcp -update like) and update_strategy=strict.
   - Support compare_mode=len_mtime and compare_mode=checksum (checksum only valid for strict).
   
   
   <!-- Describe the purpose of this pull request. For example: This pull request adds checkstyle plugin.-->
   
   
   ### Does this PR introduce _any_ user-facing change?
   Yes.
   
   New source options: sync_mode/target_path/target_hadoop_conf/update_strategy/compare_mode.
   Default behavior unchanged (sync_mode=full).
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released SeaTunnel versions or within the unreleased branches such as dev.
   If no, write 'No'.
   If you are adding/modifying connector documents, please follow our new specifications: https://github.com/apache/seatunnel/issues/4544.
   -->
   
   
   ### How was this patch tested?
   
   - Unit test (Windows skipped by design; CI Linux will run): mvnw -pl seatunnel-connectors-v2/connector-file/connector-file-base test -Dtest=UpdateSyncModeTest
   
   - Added E2E tests (run in CI/Docker env): HdfsFileIT#testHdfsBinaryUpdateModeDistcp / HdfsFileIT#testHdfsBinaryUpdateModeStrictChecksum.
   
   
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If you are adding E2E test cases, maybe refer to https://github.com/apache/seatunnel/blob/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-cdc-mysql-e2e/src/test/resources/mysqlcdc_to_mysql.conf, here is a good example.
   -->
   
   
   ### Check list
   
   * [ ] If any new Jar binary package adding in your PR, please add License Notice according
     [New License Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/contribution/new-license.md)
   * [ * ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/seatunnel/tree/dev/docs
   * [ ] If necessary, please update `incompatible-changes.md` to describe the incompatibility caused by this PR.
   * [ ] If you are contributing the connector code, please check that the following files are updated:
     1. Update [plugin-mapping.properties](https://github.com/apache/seatunnel/blob/dev/plugin-mapping.properties) and add new connector information in it
     2. Update the pom file of [seatunnel-dist](https://github.com/apache/seatunnel/blob/dev/seatunnel-dist/pom.xml)
     3. Add ci label in [label-scope-conf](https://github.com/apache/seatunnel/blob/dev/.github/workflows/labeler/label-scope-conf.yml)
     4. Add e2e testcase in [seatunnel-e2e](https://github.com/apache/seatunnel/tree/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/)
     5. Update connector [plugin_config](https://github.com/apache/seatunnel/blob/dev/config/plugin_config)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][Connector-File-Hadoop] Support sync_mode=update for HdfsFile source (binary) [seatunnel]

Posted by "zhangshenghang (via GitHub)" <gi...@apache.org>.
zhangshenghang commented on code in PR #10268:
URL: https://github.com/apache/seatunnel/pull/10268#discussion_r2661498067


##########
seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/reader/AbstractReadStrategy.java:
##########
@@ -470,10 +520,304 @@ protected static InputStream safeSlice(InputStream in, long start, long length)
     @Override
     public void close() throws IOException {
         try {
+            if (targetHadoopFileSystemProxy != null && !shareTargetFileSystemProxy) {
+                targetHadoopFileSystemProxy.close();
+            }
             if (hadoopFileSystemProxy != null) {
                 hadoopFileSystemProxy.close();
             }
         } catch (Exception ignore) {
         }
     }
+
+    private void validateUpdateSyncConfig(Config pluginConfig) {
+        if (!pluginConfig.hasPath(FileBaseSourceOptions.FILE_FORMAT_TYPE.key())) {
+            throw new FileConnectorException(
+                    SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED,
+                    "When sync_mode=update, file_format_type must be set.");
+        }
+        FileFormat fileFormat =
+                FileFormat.valueOf(
+                        pluginConfig
+                                .getString(FileBaseSourceOptions.FILE_FORMAT_TYPE.key())
+                                .toUpperCase());
+        if (fileFormat != FileFormat.BINARY) {
+            throw new FileConnectorException(
+                    SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED,
+                    "sync_mode=update currently only supports file_format_type=binary.");
+        }
+
+        if (!pluginConfig.hasPath(FileBaseSourceOptions.TARGET_PATH.key())
+                || StringUtils.isBlank(
+                        pluginConfig.getString(FileBaseSourceOptions.TARGET_PATH.key()))) {
+            throw new FileConnectorException(
+                    SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED,
+                    "When sync_mode=update, target_path must be set.");
+        }
+        targetPath = pluginConfig.getString(FileBaseSourceOptions.TARGET_PATH.key()).trim();
+
+        updateStrategy = FileBaseSourceOptions.UPDATE_STRATEGY.defaultValue();
+        if (pluginConfig.hasPath(FileBaseSourceOptions.UPDATE_STRATEGY.key())) {
+            updateStrategy =
+                    parseEnumValue(
+                            FileUpdateStrategy.class,
+                            pluginConfig.getString(FileBaseSourceOptions.UPDATE_STRATEGY.key()),
+                            FileBaseSourceOptions.UPDATE_STRATEGY.key());
+        }
+
+        compareMode = FileBaseSourceOptions.COMPARE_MODE.defaultValue();
+        if (pluginConfig.hasPath(FileBaseSourceOptions.COMPARE_MODE.key())) {
+            compareMode =
+                    parseEnumValue(
+                            FileCompareMode.class,
+                            pluginConfig.getString(FileBaseSourceOptions.COMPARE_MODE.key()),
+                            FileBaseSourceOptions.COMPARE_MODE.key());
+        }
+        if (updateStrategy == FileUpdateStrategy.DISTCP
+                && compareMode != FileCompareMode.LEN_MTIME) {
+            throw new FileConnectorException(
+                    SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED,
+                    "compare_mode="
+                            + compareMode.name().toLowerCase(Locale.ROOT)
+                            + " is not supported when update_strategy=distcp.");
+        }
+
+        if (pluginConfig.hasPath(FileBaseSourceOptions.TARGET_HADOOP_CONF.key())) {
+            ConfigObject configObject =
+                    pluginConfig.getObject(FileBaseSourceOptions.TARGET_HADOOP_CONF.key());
+            Map<String, Object> raw = configObject.unwrapped();
+            Map<String, String> conf = new LinkedHashMap<>(raw.size());
+            raw.forEach((k, v) -> conf.put(k, v == null ? null : String.valueOf(v)));
+            targetHadoopConf = conf;
+        }
+    }
+
+    private void initTargetHadoopFileSystemProxy() {
+        HadoopConf targetConf = buildTargetHadoopConf();
+        if (targetConf == this.hadoopConf) {
+            targetHadoopFileSystemProxy = this.hadoopFileSystemProxy;
+            shareTargetFileSystemProxy = true;
+        } else {
+            targetHadoopFileSystemProxy = new HadoopFileSystemProxy(targetConf);
+            shareTargetFileSystemProxy = false;
+        }
+    }
+
+    private HadoopConf buildTargetHadoopConf() {
+        if (!enableUpdateSync) {
+            return this.hadoopConf;
+        }
+        Map<String, String> extraOptions =
+                targetHadoopConf == null
+                        ? new LinkedHashMap<>()
+                        : new LinkedHashMap<>(targetHadoopConf);
+
+        String fsDefaultNameKey = hadoopConf.getFsDefaultNameKey();
+        String targetDefaultFs = extraOptions.remove(fsDefaultNameKey);
+
+        if (StringUtils.isBlank(targetDefaultFs)) {
+            targetDefaultFs = tryDeriveDefaultFsFromPath(targetPath);
+        }
+        if (StringUtils.isBlank(targetDefaultFs)) {
+            targetDefaultFs = hadoopConf.getHdfsNameKey();
+        }
+
+        boolean needNewConf =
+                !extraOptions.isEmpty()
+                        || !Objects.equals(targetDefaultFs, hadoopConf.getHdfsNameKey());
+        if (!needNewConf) {
+            return this.hadoopConf;
+        }
+
+        HadoopConf conf = new HadoopConf(targetDefaultFs);
+        conf.setHdfsSitePath(hadoopConf.getHdfsSitePath());
+        conf.setRemoteUser(hadoopConf.getRemoteUser());
+        conf.setKrb5Path(hadoopConf.getKrb5Path());
+        conf.setKerberosPrincipal(hadoopConf.getKerberosPrincipal());
+        conf.setKerberosKeytabPath(hadoopConf.getKerberosKeytabPath());
+        conf.setExtraOptions(extraOptions);
+        return conf;
+    }
+
+    private static String tryDeriveDefaultFsFromPath(String basePath) {
+        if (StringUtils.isBlank(basePath)) {
+            return null;
+        }
+        try {
+            Path path = new Path(basePath);
+            if (path.toUri().getScheme() == null) {
+                return null;
+            }
+            if (path.toUri().getAuthority() == null) {
+                return null;
+            }
+            return path.toUri().getScheme() + "://" + path.toUri().getAuthority();
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    private boolean shouldSyncFileInUpdateMode(FileStatus sourceFileStatus) throws IOException {
+        if (!enableUpdateSync) {
+            return true;
+        }
+        if (targetHadoopFileSystemProxy == null) {
+            initTargetHadoopFileSystemProxy();
+        }
+        String sourceFilePath = sourceFileStatus.getPath().toString();
+        String relativePath = resolveRelativePath(sourceRootPath, sourceFilePath);
+        String targetFilePath = buildTargetFilePath(targetPath, relativePath);
+
+        FileStatus targetFileStatus;
+        try {
+            targetFileStatus = targetHadoopFileSystemProxy.getFileStatus(targetFilePath);
+        } catch (FileNotFoundException e) {
+            return true;
+        }
+
+        long sourceLen = sourceFileStatus.getLen();
+        long targetLen = targetFileStatus.getLen();
+        if (sourceLen != targetLen) {
+            return true;
+        }
+
+        long sourceMtime = sourceFileStatus.getModificationTime();
+        long targetMtime = targetFileStatus.getModificationTime();
+
+        if (updateStrategy == FileUpdateStrategy.DISTCP) {
+            return sourceMtime > targetMtime;
+        }
+
+        if (updateStrategy == FileUpdateStrategy.STRICT) {
+            if (compareMode == FileCompareMode.LEN_MTIME) {
+                return sourceMtime != targetMtime;
+            }
+            if (compareMode == FileCompareMode.CHECKSUM) {
+                FileChecksum sourceChecksum = hadoopFileSystemProxy.getFileChecksum(sourceFilePath);
+                FileChecksum targetChecksum =
+                        targetHadoopFileSystemProxy.getFileChecksum(targetFilePath);
+                if (sourceChecksum == null || targetChecksum == null) {
+                    if (!checksumUnavailableWarned) {
+                        log.warn(
+                                "File checksum is not available, fallback to content comparison. source={}, target={}",
+                                sourceFilePath,
+                                targetFilePath);
+                        checksumUnavailableWarned = true;
+                    }
+                    try {
+                        return !fileContentEquals(sourceFilePath, targetFilePath);
+                    } catch (Exception e) {
+                        log.warn(
+                                "Fallback content comparison failed, fallback to COPY. source={}, target={}",
+                                sourceFilePath,
+                                targetFilePath,
+                                e);
+                        return true;
+                    }
+                }
+                return !checksumEquals(sourceChecksum, targetChecksum);
+            }
+        }
+
+        return true;
+    }
+
+    private static boolean checksumEquals(FileChecksum source, FileChecksum target) {
+        if (source == null || target == null) {
+            return false;
+        }
+        return Objects.equals(source.getAlgorithmName(), target.getAlgorithmName())
+                && source.getLength() == target.getLength()
+                && Arrays.equals(source.getBytes(), target.getBytes());
+    }
+
+    private boolean fileContentEquals(String sourceFilePath, String targetFilePath)
+            throws IOException {
+        try (InputStream sourceIn = hadoopFileSystemProxy.getInputStream(sourceFilePath);
+                InputStream targetIn = targetHadoopFileSystemProxy.getInputStream(targetFilePath)) {
+            byte[] sourceBuffer = new byte[8 * 1024];
+            byte[] targetBuffer = new byte[8 * 1024];
+
+            while (true) {
+                int sourceRead = sourceIn.read(sourceBuffer);
+                int targetRead = targetIn.read(targetBuffer);
+                if (sourceRead != targetRead) {
+                    return false;
+                }
+                if (sourceRead == -1) {
+                    return true;
+                }
+                for (int i = 0; i < sourceRead; i++) {
+                    if (sourceBuffer[i] != targetBuffer[i]) {
+                        return false;
+                    }
+                }
+            }
+        }
+    }

Review Comment:
   If it is downgraded to file byte comparison, if the file is large, it may lead to high memory usage. Is there a risk of OOM?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][Connector-File-Hadoop] Support sync_mode=update for HdfsFile source (binary) [seatunnel]

Posted by "zhangshenghang (via GitHub)" <gi...@apache.org>.
zhangshenghang merged PR #10268:
URL: https://github.com/apache/seatunnel/pull/10268


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][Connector-File-Hadoop] Support sync_mode=update for HdfsFile source (binary) [seatunnel]

Posted by "yzeng1618 (via GitHub)" <gi...@apache.org>.
yzeng1618 commented on code in PR #10268:
URL: https://github.com/apache/seatunnel/pull/10268#discussion_r2661542041


##########
seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/reader/AbstractReadStrategy.java:
##########
@@ -470,10 +520,304 @@ protected static InputStream safeSlice(InputStream in, long start, long length)
     @Override
     public void close() throws IOException {
         try {
+            if (targetHadoopFileSystemProxy != null && !shareTargetFileSystemProxy) {
+                targetHadoopFileSystemProxy.close();
+            }
             if (hadoopFileSystemProxy != null) {
                 hadoopFileSystemProxy.close();
             }
         } catch (Exception ignore) {
         }
     }
+
+    private void validateUpdateSyncConfig(Config pluginConfig) {
+        if (!pluginConfig.hasPath(FileBaseSourceOptions.FILE_FORMAT_TYPE.key())) {
+            throw new FileConnectorException(
+                    SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED,
+                    "When sync_mode=update, file_format_type must be set.");
+        }
+        FileFormat fileFormat =
+                FileFormat.valueOf(
+                        pluginConfig
+                                .getString(FileBaseSourceOptions.FILE_FORMAT_TYPE.key())
+                                .toUpperCase());
+        if (fileFormat != FileFormat.BINARY) {
+            throw new FileConnectorException(
+                    SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED,
+                    "sync_mode=update currently only supports file_format_type=binary.");
+        }
+
+        if (!pluginConfig.hasPath(FileBaseSourceOptions.TARGET_PATH.key())
+                || StringUtils.isBlank(
+                        pluginConfig.getString(FileBaseSourceOptions.TARGET_PATH.key()))) {
+            throw new FileConnectorException(
+                    SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED,
+                    "When sync_mode=update, target_path must be set.");
+        }
+        targetPath = pluginConfig.getString(FileBaseSourceOptions.TARGET_PATH.key()).trim();
+
+        updateStrategy = FileBaseSourceOptions.UPDATE_STRATEGY.defaultValue();
+        if (pluginConfig.hasPath(FileBaseSourceOptions.UPDATE_STRATEGY.key())) {
+            updateStrategy =
+                    parseEnumValue(
+                            FileUpdateStrategy.class,
+                            pluginConfig.getString(FileBaseSourceOptions.UPDATE_STRATEGY.key()),
+                            FileBaseSourceOptions.UPDATE_STRATEGY.key());
+        }
+
+        compareMode = FileBaseSourceOptions.COMPARE_MODE.defaultValue();
+        if (pluginConfig.hasPath(FileBaseSourceOptions.COMPARE_MODE.key())) {
+            compareMode =
+                    parseEnumValue(
+                            FileCompareMode.class,
+                            pluginConfig.getString(FileBaseSourceOptions.COMPARE_MODE.key()),
+                            FileBaseSourceOptions.COMPARE_MODE.key());
+        }
+        if (updateStrategy == FileUpdateStrategy.DISTCP
+                && compareMode != FileCompareMode.LEN_MTIME) {
+            throw new FileConnectorException(
+                    SeaTunnelAPIErrorCode.CONFIG_VALIDATION_FAILED,
+                    "compare_mode="
+                            + compareMode.name().toLowerCase(Locale.ROOT)
+                            + " is not supported when update_strategy=distcp.");
+        }
+
+        if (pluginConfig.hasPath(FileBaseSourceOptions.TARGET_HADOOP_CONF.key())) {
+            ConfigObject configObject =
+                    pluginConfig.getObject(FileBaseSourceOptions.TARGET_HADOOP_CONF.key());
+            Map<String, Object> raw = configObject.unwrapped();
+            Map<String, String> conf = new LinkedHashMap<>(raw.size());
+            raw.forEach((k, v) -> conf.put(k, v == null ? null : String.valueOf(v)));
+            targetHadoopConf = conf;
+        }
+    }
+
+    private void initTargetHadoopFileSystemProxy() {
+        HadoopConf targetConf = buildTargetHadoopConf();
+        if (targetConf == this.hadoopConf) {
+            targetHadoopFileSystemProxy = this.hadoopFileSystemProxy;
+            shareTargetFileSystemProxy = true;
+        } else {
+            targetHadoopFileSystemProxy = new HadoopFileSystemProxy(targetConf);
+            shareTargetFileSystemProxy = false;
+        }
+    }
+
+    private HadoopConf buildTargetHadoopConf() {
+        if (!enableUpdateSync) {
+            return this.hadoopConf;
+        }
+        Map<String, String> extraOptions =
+                targetHadoopConf == null
+                        ? new LinkedHashMap<>()
+                        : new LinkedHashMap<>(targetHadoopConf);
+
+        String fsDefaultNameKey = hadoopConf.getFsDefaultNameKey();
+        String targetDefaultFs = extraOptions.remove(fsDefaultNameKey);
+
+        if (StringUtils.isBlank(targetDefaultFs)) {
+            targetDefaultFs = tryDeriveDefaultFsFromPath(targetPath);
+        }
+        if (StringUtils.isBlank(targetDefaultFs)) {
+            targetDefaultFs = hadoopConf.getHdfsNameKey();
+        }
+
+        boolean needNewConf =
+                !extraOptions.isEmpty()
+                        || !Objects.equals(targetDefaultFs, hadoopConf.getHdfsNameKey());
+        if (!needNewConf) {
+            return this.hadoopConf;
+        }
+
+        HadoopConf conf = new HadoopConf(targetDefaultFs);
+        conf.setHdfsSitePath(hadoopConf.getHdfsSitePath());
+        conf.setRemoteUser(hadoopConf.getRemoteUser());
+        conf.setKrb5Path(hadoopConf.getKrb5Path());
+        conf.setKerberosPrincipal(hadoopConf.getKerberosPrincipal());
+        conf.setKerberosKeytabPath(hadoopConf.getKerberosKeytabPath());
+        conf.setExtraOptions(extraOptions);
+        return conf;
+    }
+
+    private static String tryDeriveDefaultFsFromPath(String basePath) {
+        if (StringUtils.isBlank(basePath)) {
+            return null;
+        }
+        try {
+            Path path = new Path(basePath);
+            if (path.toUri().getScheme() == null) {
+                return null;
+            }
+            if (path.toUri().getAuthority() == null) {
+                return null;
+            }
+            return path.toUri().getScheme() + "://" + path.toUri().getAuthority();
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    private boolean shouldSyncFileInUpdateMode(FileStatus sourceFileStatus) throws IOException {
+        if (!enableUpdateSync) {
+            return true;
+        }
+        if (targetHadoopFileSystemProxy == null) {
+            initTargetHadoopFileSystemProxy();
+        }
+        String sourceFilePath = sourceFileStatus.getPath().toString();
+        String relativePath = resolveRelativePath(sourceRootPath, sourceFilePath);
+        String targetFilePath = buildTargetFilePath(targetPath, relativePath);
+
+        FileStatus targetFileStatus;
+        try {
+            targetFileStatus = targetHadoopFileSystemProxy.getFileStatus(targetFilePath);
+        } catch (FileNotFoundException e) {
+            return true;
+        }
+
+        long sourceLen = sourceFileStatus.getLen();
+        long targetLen = targetFileStatus.getLen();
+        if (sourceLen != targetLen) {
+            return true;
+        }
+
+        long sourceMtime = sourceFileStatus.getModificationTime();
+        long targetMtime = targetFileStatus.getModificationTime();
+
+        if (updateStrategy == FileUpdateStrategy.DISTCP) {
+            return sourceMtime > targetMtime;
+        }
+
+        if (updateStrategy == FileUpdateStrategy.STRICT) {
+            if (compareMode == FileCompareMode.LEN_MTIME) {
+                return sourceMtime != targetMtime;
+            }
+            if (compareMode == FileCompareMode.CHECKSUM) {
+                FileChecksum sourceChecksum = hadoopFileSystemProxy.getFileChecksum(sourceFilePath);
+                FileChecksum targetChecksum =
+                        targetHadoopFileSystemProxy.getFileChecksum(targetFilePath);
+                if (sourceChecksum == null || targetChecksum == null) {
+                    if (!checksumUnavailableWarned) {
+                        log.warn(
+                                "File checksum is not available, fallback to content comparison. source={}, target={}",
+                                sourceFilePath,
+                                targetFilePath);
+                        checksumUnavailableWarned = true;
+                    }
+                    try {
+                        return !fileContentEquals(sourceFilePath, targetFilePath);
+                    } catch (Exception e) {
+                        log.warn(
+                                "Fallback content comparison failed, fallback to COPY. source={}, target={}",
+                                sourceFilePath,
+                                targetFilePath,
+                                e);
+                        return true;
+                    }
+                }
+                return !checksumEquals(sourceChecksum, targetChecksum);
+            }
+        }
+
+        return true;
+    }
+
+    private static boolean checksumEquals(FileChecksum source, FileChecksum target) {
+        if (source == null || target == null) {
+            return false;
+        }
+        return Objects.equals(source.getAlgorithmName(), target.getAlgorithmName())
+                && source.getLength() == target.getLength()
+                && Arrays.equals(source.getBytes(), target.getBytes());
+    }
+
+    private boolean fileContentEquals(String sourceFilePath, String targetFilePath)
+            throws IOException {
+        try (InputStream sourceIn = hadoopFileSystemProxy.getInputStream(sourceFilePath);
+                InputStream targetIn = targetHadoopFileSystemProxy.getInputStream(targetFilePath)) {
+            byte[] sourceBuffer = new byte[8 * 1024];
+            byte[] targetBuffer = new byte[8 * 1024];
+
+            while (true) {
+                int sourceRead = sourceIn.read(sourceBuffer);
+                int targetRead = targetIn.read(targetBuffer);
+                if (sourceRead != targetRead) {
+                    return false;
+                }
+                if (sourceRead == -1) {
+                    return true;
+                }
+                for (int i = 0; i < sourceRead; i++) {
+                    if (sourceBuffer[i] != targetBuffer[i]) {
+                        return false;
+                    }
+                }
+            }
+        }
+    }

Review Comment:
   Memory usage here is constant: we compare via streaming reads with two fixed 8KB buffers (no full-file buffering), so large files shouldn’t cause OOM—only more I/O time.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][Connector-File-Hadoop] Support sync_mode=update for HdfsFile source (binary) [seatunnel]

Posted by "davidzollo (via GitHub)" <gi...@apache.org>.
davidzollo commented on PR #10268:
URL: https://github.com/apache/seatunnel/pull/10268#issuecomment-3719165434

   <img width="1582" height="558" alt="image" src="https://github.com/user-attachments/assets/9d29d822-bb06-46fa-9e4c-b24584f6b9eb" />
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org