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

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

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


##########
hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterTrash.java:
##########
@@ -144,6 +145,95 @@ private boolean addMountTable(final MountTable entry) 
throws IOException {
     return addResponse.getStatus();
   }
 
+  /**
+   * We manually create the trash root for TEST_USER. Then, moveToTrash
+   * shall not cause the router to create user's home dir anymore.
+   *
+   * We compare the modification of user home dir before and after moveToTrash,
+   * to verify that we don't try to re-create user home dir once it already
+   * exists. We need to pre-create the trash root, instead of user home dir,
+   * because adding a subdir to a dir will change the dir's modification time.
+   */
+  @Test
+  public void testMoveToTrashAutoCreateUserHomeAlreadyExisted()
+      throws IOException, URISyntaxException, InterruptedException {
+    MountTable addEntry = MountTable.newInstance(MOUNT_POINT,
+        Collections.singletonMap(ns0, MOUNT_POINT));
+    assertTrue(addMountTable(addEntry));
+    String testUserHome = "/user/" + TEST_USER;
+    String testUserTrashRoot = testUserHome + "/.Trash";
+
+    // Set owner to TEST_USER for root dir
+    DFSClient superUserClient = nnContext.getClient();
+    superUserClient.setOwner("/", TEST_USER, TEST_USER);
+
+    // Create MOUNT_POINT and user's trash root
+    UserGroupInformation ugi = 
UserGroupInformation.createRemoteUser(TEST_USER);
+    DFSClient client = nnContext.getClient(ugi);
+    client.mkdirs(MOUNT_POINT, new FsPermission("777"), true);
+    assertTrue(client.exists(MOUNT_POINT));
+    client.mkdirs(testUserTrashRoot, new FsPermission("775"), true);
+    assertTrue(client.exists(testUserTrashRoot));
+
+    // Create test file
+    client.create(FILE, true);
+    Path filePath = new Path(FILE);
+
+    // Get the fileStatus before moveToTrash
+    HdfsFileStatus status = client.getFileInfo(testUserHome);
+
+    // Test moveToTrash by TEST_USER
+    String trashPath = "/user/" + TEST_USER + "/.Trash/Current" + FILE;
+    Configuration routerConf = routerContext.getConf();
+    FileSystem fs = DFSTestUtil.getFileSystemAs(ugi, routerConf);
+    Trash trash = new Trash(fs, routerConf);
+    assertTrue(trash.moveToTrash(filePath));
+    assertTrue(nnFs.exists(new Path(trashPath)));
+
+    HdfsFileStatus status2 = client.getFileInfo(testUserHome);
+    assertEquals(status.getModificationTime(), status2.getModificationTime());

Review Comment:
   Does modtime change if the directory already exists? i.e. we do an "if not 
exists create"
   
   This can be unit tested with mocks where we mock out the rpc client to 
observe what is actually called to avoid this ambiguity. 





> 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