You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2021/11/01 08:03:00 UTC

[jira] [Work logged] (SSHD-1220) SFTP: too many LSTAT calls

     [ https://issues.apache.org/jira/browse/SSHD-1220?focusedWorklogId=672571&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-672571 ]

ASF GitHub Bot logged work on SSHD-1220:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 01/Nov/21 08:02
            Start Date: 01/Nov/21 08:02
    Worklog Time Spent: 10m 
      Work Description: tomaswolf commented on a change in pull request #207:
URL: https://github.com/apache/mina-sshd/pull/207#discussion_r740020319



##########
File path: docs/sftp.md
##########
@@ -532,7 +530,27 @@ if (directoryPath instanceof SftpPath) {
   // Not an SFTP path -- get the directory listing in whatever other way is appropriate.
 }
 ```
-So even if an `SftpFileSystem` fulfills the general contract of a `FileSystem`, a client still has to be aware that
+Alternatively, one can also use the fact that Apache MINA sshd caches the SFTP file attributes on the `SftpPath` objects it
+returns from a `DirectoryStream`:
+
+```java
+public void processSftpDirectory(SftpPath directoryPath, BiConsumer<Path, SftpClient.Attributes> process) throws IOException {
+  try (DirectoryStream<Path> dir = Files.newDirectoryStream(directoryPath)) {
+    for (Path path : dir) {
+      if (path instanceof SftpPath) {
+        SftpClient.Attributes attributes = ((SftpPath) path).getAttributes();
+        process.accept(path, attributes);
+      } else {
+        // A DirectoryStream on a directory given by an SftpPath always returns SftpPath instances as elements.
+        throw new IllegalStateException();

Review comment:
       Done.




-- 
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: dev-unsubscribe@mina.apache.org

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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 672571)
    Time Spent: 2h 40m  (was: 2.5h)

> SFTP: too many LSTAT calls
> --------------------------
>
>                 Key: SSHD-1220
>                 URL: https://issues.apache.org/jira/browse/SSHD-1220
>             Project: MINA SSHD
>          Issue Type: Improvement
>    Affects Versions: 2.7.0
>            Reporter: Thomas Wolf
>            Assignee: Thomas Wolf
>            Priority: Major
>          Time Spent: 2h 40m
>  Remaining Estimate: 0h
>
> While looking at an alternate solution for SSHD-1217 I noticed that the {{AbstractSftpSubsystemHelper}} makes several LSTAT calls for a single {{FileSystem.readAttributes()}} invocation.
> Basically it makes one LSTAT call per supported attributes view; only to collect the returned items then in one single map anyway.
> This doesn't make any sense. SFTP file attributes are a single, defined structure. If {{AbstractSftpSubsystemHelper.getAttributes()}} needs to collect all these different views ({{BasicFileAttributes}}, {{PosixFileAttributes}}, and so on) on these underlying SFTP attributes, then all these views should build upon the same single {{SftpClient.Attributes}} gotten exactly _once_.
> This could be solved with careful temporary caching of SFTP attributes on the {{SftpPath}} once read while in {{AbstractSftpSubsystemHelper.getAttributes()}} and clearing that cache at the end.
> The problem is more general, though. The code in several places makes up-front checks whether a file exists, is a directory, and so on. This is a questionable pattern anyway, since the result of a {{Files.exists()}} is outdated immediately; one cannot rely on the file being still there on the next access. With an {{SftpPath}}, this {{exists()}} call is an (L)STAT remote call getting the attributes. Now look at {{AbstractSftpSubsystemHelper.resolveFileAttributes}}: here getting the attributes themselves is so guarded, so it makes at least _two_ LSTAT calls.
> This should also be improved.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org