[ 
https://issues.apache.org/jira/browse/HDFS-16816?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17624654#comment-17624654
 ] 

ASF GitHub Bot commented on HDFS-16816:
---------------------------------------

mkuchenbecker commented on code in PR #5071:
URL: https://github.com/apache/hadoop/pull/5071#discussion_r1006014094


##########
hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterClientProtocol.java:
##########
@@ -723,6 +723,78 @@ public boolean delete(String src, boolean recursive) 
throws IOException {
     }
   }
 
+  /**
+   * Create missing user home dirs for trash paths.
+   *
+   * When there are multiple possible destination locations for a trash path,
+   * we create user home dirs at all destination locations.
+   *
+   * We assume the router is running with super-user privilege (can create
+   * user home dir in /user dir).
+   *
+   * @param src source location
+   * @param locations destination locations
+   */
+  private void createUserHomeForTrashPath(String src,
+      List<RemoteLocation> locations)
+      throws IOException {
+    List<RemoteLocation> userHomes = new ArrayList<>();
+    List<RemoteLocation> missingUserHomes = new ArrayList<>();
+
+    // Get home dirs for trash paths
+    for (RemoteLocation loc : locations) {
+
+      String path = loc.getDest();
+      // Continue if not a trash path
+      if (!MountTableResolver.isTrashPath(path)) {
+        continue;
+      }
+
+      String trashRoot = MountTableResolver.getTrashRoot();
+      String userHome = new Path(trashRoot).getParent().toUri().getPath();
+      RemoteLocation userHomeLoc = new RemoteLocation(loc, userHome);
+      userHomes.add(userHomeLoc);
+    }
+
+    // Use getFileInfo to identify missing user homes
+    for (RemoteLocation userHomeLoc : userHomes) {
+      RemoteMethod method =
+          new RemoteMethod("getFileInfo", new Class<?>[]{String.class},
+              new RemoteParam());
+      HdfsFileStatus ret =
+          rpcClient.invokeSingle(userHomeLoc, method, HdfsFileStatus.class);
+      if (ret == null) {
+        missingUserHomes.add(userHomeLoc);
+      }
+    }
+
+    // Create missing user home dirs and set owner
+    for(RemoteLocation loc: missingUserHomes) {

Review Comment:
   My concern is this function is doing too much and is hard to test; it first 
creates / filters a list (involves IO) and then creates directories (Also IO). 
The logic that involces IO can be encapsulated with a lambda so we can test the 
logic of the function in-isolation of the result of the IO. Alternatively we 
can mock the RPC client to observe what is actually called by this function. 





> RBF: auto-create user home dir for trash paths by router
> --------------------------------------------------------
>
>                 Key: HDFS-16816
>                 URL: https://issues.apache.org/jira/browse/HDFS-16816
>             Project: Hadoop HDFS
>          Issue Type: Improvement
>          Components: rbf
>            Reporter: Xing Lin
>            Priority: Minor
>              Labels: pull-request-available
>
> In RBF, trash files are moved to trash root under user's home dir at the 
> corresponding namespace/namenode where the files reside. This was added in 
> HDFS-16024. When the user home dir is not created before-hand at a namenode, 
> we run into permission denied exceptions when trying to create the parent dir 
> for the trash file before moving the file into it. We propose to enhance 
> Router, to auto-create a user home's dir at the namenode for trash paths, 
> using router's identity (which is assumed to be a super-user).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: hdfs-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: hdfs-issues-h...@hadoop.apache.org

Reply via email to