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

   Yes, I am contributing to SeaTunnel.
   
   ### Purpose of this pull request
   
   Closes #13769
   
   `SFTPFileSystem.open()` decides whether a path is a directory through the 
private `getFileStatus(ChannelSftp, Path)`. That method lists the **whole 
parent directory** with `ChannelSftp.ls()` and scans the entries for the file 
name. The source calls `open()` once per file it reads, so reading N files from 
one directory lists that directory N times, and the cost per file grows with 
the size of the directory.
   
   This PR makes `open()` ask the server about the single path with 
`ChannelSftp.lstat()` instead of listing the parent directory:
   
   - The path is quoted first (`quote()`), because JSch treats `*` and `?` in 
`lstat` as globs and fails with "not unique" (the problem #8501 fixed for 
`get`).
   - Symbolic links are still resolved by the existing status builder, which 
calls `realpath` for a link.
   - Any SFTP failure is still reported as `FileNotFoundException`, as before.
   - The other callers of `getFileStatus` (`exists`, `isFile`, `delete`, 
`listStatus`, `mkdirs`) are unchanged. The scope is `open()` only.
   
   Measured on an SFTP server in the same cluster as the client (mean of 100 
`open()` + read calls, baseline and patched builds run alternately, 2 runs 
each):
   
   | Entries per directory | Current | With `lstat` | Time reduced |
   |---|---|---|---|
   | 100 | 11.5 - 13.0 ms | 6.3 - 7.0 ms | ~46% |
   | 1,000 | 28.4 - 28.9 ms | 7.5 - 7.7 ms | ~73% |
   | 5,000 | 87.7 - 102.2 ms | 7.4 - 9.4 ms | ~91% |
   
   The server was close to the client, so round-trip latency was low. A remote 
server should show a larger difference, but I have not measured it.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No configuration option, default, or public API changes. There is one 
behavior difference compared with the released versions and with current `dev`, 
and I would like reviewers to decide whether it is acceptable:
   
   - **A directory with execute permission but no read permission (`--x`).** 
Previously `open()` on a file inside such a directory failed with 
`FileNotFoundException`, because the parent directory listing was denied. Now 
the file can be opened, because only the file itself is looked up. On POSIX, 
execute permission on a directory is enough to access a file whose name you 
already know, so the old failure looks like an over-strict side effect of 
listing the parent. I am happy to keep the old behavior if reviewers prefer.
   
   I compared the previous and the new build on the same server with 22 cases 
(special characters, relative/absolute/chained symlinks, a link to a directory, 
a broken link, missing files, directories with mode 000/311/644, and a file 
with mode 000). 21 behave identically. The `--x` directory is the only 
difference.
   
   Error mapping is intentionally unchanged (for example, a permission failure 
is still reported as `FileNotFoundException`). Reporting it as "permission 
denied" would change behavior and can be a separate change if reviewers want it.
   
   Compatibility: no option, data format, or SPI changes. The change is 
confined to `SFTPFileSystem.open()` in `connector-file-sftp`.
   
   ### How was this patch tested?
   
   Unit tests were added to the existing `SftpFileSystemTest` (no new class). 
They use a mocked `ChannelSftp` and cover:
   
   - `open()` calls `lstat` once and does not call `ls` on the parent directory
   - a file name containing `*` is quoted before `lstat`
   - a missing file and a permission failure are both reported as 
`FileNotFoundException`
   - a directory and a symbolic link to a directory are rejected with "is a 
directory"
   - a symbolic link to a file reads the target content
   
   The new tests failed before the change and pass after it.
   
   Checked locally on an amd64 JDK 11 runner (Maven 3.8.4):
   
   - Unit tests of the SFTP module and its dependent modules, using the same 
Maven command as the CI unit-test job: 30 tests passed.
   - `spotless:check` passed.
   - `./mvnw verify -DskipTests` of the whole repository (339 modules): BUILD 
SUCCESS.
   
   I did not run the full-repository unit tests or JDK 17 myself and am relying 
on CI for them.
   
   No E2E test was added or changed. `SftpFileIT` already reads and writes 
through `SFTPFileSystem.open()`, including a file whose name contains wildcard 
characters (added in #8501). This change adds no option or behavior to 
configure, so I did not add a new IT. I am happy to add one if reviewers want 
it.
   
   The 22-case comparison and the timings above were run against an SFTP server 
container in a Kubernetes cluster.
   
   ### Check list
   
   * [x] 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/developer/new-license.md)
 (no new dependency)
   * [x] If necessary, please update the documentation to describe the new 
feature. (not needed: no option, default, or documented behavior changes)
   * [ ] If necessary, please update `incompatible-changes.md` to describe the 
incompatibility caused by this PR. (left to reviewers: the `--x` case above)
   * [x] If you are contributing the connector code, please check that the 
following files are updated: (not applicable: no new connector)
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to