Hean-Chhinling commented on code in PR #8798:
URL: https://github.com/apache/hadoop/pull/8798#discussion_r4315362999


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/DirectoryCollection.java:
##########
@@ -593,25 +600,97 @@ private DiskErrorInformation 
validateSubsAccessibility(File dir) {
     if (!subAccessibilityValidationEnabled) {
       return null;
     }
-    try (Stream<java.nio.file.Path> walk = Files.walk(dir.toPath())) {
-      List<File> subs = walk
-          .map(java.nio.file.Path::toFile)
-          .collect(Collectors.toList());
-      for (File sub : subs) {
-        if (sub.isDirectory()) {
-          DiskChecker.checkDir(sub);
-        } else if (!Files.isReadable(sub.toPath())) {
-          return new DiskErrorInformation(DiskErrorCause.OTHER, "Can not read 
" + sub);
-        } else {
-          LOG.debug("{} under {} is accessible", sub, dir);
-        }
-      }
+    LOG.debug("Start checking accessibility for: {}", dir);
+
+    try {
+      Files.walkFileTree(dir.toPath(), Collections.emptySet(),
+          subAccessibilityValidationMaxDepth, new SubAccessibilityVisitor());
     } catch (IOException | UncheckedIOException | SecurityException e) {
       return new DiskErrorInformation(DiskErrorCause.OTHER, e.getMessage());
     }
     return null;
   }
 
+  /**
+   * Walks the content of an NM directories.
+   * It fails with an {@link IOException} if the NM user cannot access the 
entry.
+   * Entries must be readable, writable and executable.
+   * Symbolic links are neither followed nor checked.
+   * <p>
+   * Entries deleted during the walk are ignored, because
+   * localization and cleanup modify these directories concurrently.
+   */
+  @VisibleForTesting
+  static class SubAccessibilityVisitor
+      extends SimpleFileVisitor<java.nio.file.Path> {
+    private final String nmUser;
+
+    SubAccessibilityVisitor() {
+      this(System.getProperty("user.name"));
+    }
+
+    @VisibleForTesting
+    SubAccessibilityVisitor(String nmUser) {
+      this.nmUser = nmUser;
+    }
+
+    @Override
+    public FileVisitResult preVisitDirectory(java.nio.file.Path p,

Review Comment:
   Thanks for the suggestion, @K0K0V0K.
   I am resolving this thread, please see the comment below about the new 
changes.
   https://github.com/apache/hadoop/pull/8798#issuecomment-6270222185



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to