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

ASF GitHub Bot logged work on HDFS-15607:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 30/Sep/20 12:03
            Start Date: 30/Sep/20 12:03
    Worklog Time Spent: 10m 
      Work Description: szetszwo commented on a change in pull request #2352:
URL: https://github.com/apache/hadoop/pull/2352#discussion_r497449607



##########
File path: 
hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java
##########
@@ -2901,6 +2945,74 @@ private void provisionEZTrash(String path, FsPermission 
trashPermission)
     setPermission(trashPath, trashPermission);
   }
 
+  /**
+   * HDFS only.
+   * 
+   * Provision snapshottable directory trash.
+   * @param path Path to a snapshottable directory.
+   * @param trashPermission Expected FsPermission of the trash root.
+   * @throws IOException
+   */
+  public void provisionSnapshottableDirTrash(final Path path,
+      final FsPermission trashPermission) throws IOException {
+    Path absF = fixRelativePart(path);
+    new FileSystemLinkResolver<Void>() {
+      @Override
+      public Void doCall(Path p) throws IOException {
+        provisionSnapshottableDirTrash(getPathName(p), trashPermission);
+        return null;
+      }
+
+      @Override
+      public Void next(FileSystem fs, Path p) throws IOException {
+        if (fs instanceof DistributedFileSystem) {
+          DistributedFileSystem myDfs = (DistributedFileSystem)fs;
+          myDfs.provisionSnapshottableDirTrash(p, trashPermission);
+          return null;
+        }
+        throw new UnsupportedOperationException(
+            "Cannot provisionSnapshottableDirTrash through a symlink to" +
+            " a non-DistributedFileSystem: " + fs + " -> " + p);
+      }
+    }.resolve(this, absF);
+  }
+
+  private void provisionSnapshottableDirTrash(
+      String pathStr, FsPermission trashPermission) throws IOException {
+    Path path = new Path(pathStr);

Review comment:
       Should isSnapshotTrashRootEnabled be checked here?  If 
isSnapshotTrashRootEnabled == false, all the provisionSnapshottableDirTrash 
calls should fail.

##########
File path: 
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java
##########
@@ -1245,6 +1265,10 @@ private void printHelp(String cmd) {
     String disallowSnapshot = "-disallowSnapshot <snapshotDir>:\n" +
         "\tDo not allow snapshots to be taken on a directory any more.\n";
 
+    String provisionSnapshotTrash = "-provisionSnapshotTrash <snapshotDir>:\n" 
+
+        "\tProvision trash root in a snapshottable directory with permission"
+        + "\t777 and sticky bit.\n";

Review comment:
       Use the constant HdfsAdmin.TRASH_PERMISSION instead of harding coding it.

##########
File path: 
hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java
##########
@@ -2901,6 +2945,74 @@ private void provisionEZTrash(String path, FsPermission 
trashPermission)
     setPermission(trashPath, trashPermission);
   }
 
+  /**
+   * HDFS only.
+   * 
+   * Provision snapshottable directory trash.
+   * @param path Path to a snapshottable directory.
+   * @param trashPermission Expected FsPermission of the trash root.
+   * @throws IOException
+   */
+  public void provisionSnapshottableDirTrash(final Path path,

Review comment:
       Return the trash path.

##########
File path: 
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DFSAdmin.java
##########
@@ -782,14 +784,32 @@ public void allowSnapshot(String[] argv) throws 
IOException {
    */
   public void disallowSnapshot(String[] argv) throws IOException {
     Path p = new Path(argv[1]);
-    final DistributedFileSystem dfs = AdminHelper.getDFS(p.toUri(), getConf());
+    final HdfsAdmin admin = new HdfsAdmin(p.toUri(), getConf());
     try {
-      dfs.disallowSnapshot(p);
+      admin.disallowSnapshot(p);
     } catch (SnapshotException e) {
       throw new RemoteException(e.getClass().getName(), e.getMessage());
     }
     System.out.println("Disallowing snapshot on " + argv[1] + " succeeded");
   }
+
+  /**
+   * Provision trash root in a snapshottable directory.
+   * Usage: hdfs dfsadmin -provisionSnapshotTrash snapshotDir
+   * @param argv List of of command line parameters.
+   * @exception IOException
+   */
+  public void provisionSnapshotTrash(String[] argv) throws IOException {
+    Path p = new Path(argv[1]);
+    final HdfsAdmin admin = new HdfsAdmin(p.toUri(), getConf());
+    try {
+      admin.provisionSnapshottableDirTrash(p);
+    } catch (SnapshotException e) {
+      throw new RemoteException(e.getClass().getName(), e.getMessage());
+    }
+    System.out.println("Provision of snapshot trash in " + argv[1] +

Review comment:
       Print out the trash path.

##########
File path: 
hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java
##########
@@ -2901,6 +2945,74 @@ private void provisionEZTrash(String path, FsPermission 
trashPermission)
     setPermission(trashPath, trashPermission);
   }
 
+  /**
+   * HDFS only.
+   * 
+   * Provision snapshottable directory trash.
+   * @param path Path to a snapshottable directory.
+   * @param trashPermission Expected FsPermission of the trash root.
+   * @throws IOException
+   */
+  public void provisionSnapshottableDirTrash(final Path path,
+      final FsPermission trashPermission) throws IOException {
+    Path absF = fixRelativePart(path);
+    new FileSystemLinkResolver<Void>() {
+      @Override
+      public Void doCall(Path p) throws IOException {
+        provisionSnapshottableDirTrash(getPathName(p), trashPermission);
+        return null;
+      }
+
+      @Override
+      public Void next(FileSystem fs, Path p) throws IOException {
+        if (fs instanceof DistributedFileSystem) {
+          DistributedFileSystem myDfs = (DistributedFileSystem)fs;
+          myDfs.provisionSnapshottableDirTrash(p, trashPermission);
+          return null;
+        }
+        throw new UnsupportedOperationException(
+            "Cannot provisionSnapshottableDirTrash through a symlink to" +
+            " a non-DistributedFileSystem: " + fs + " -> " + p);
+      }
+    }.resolve(this, absF);
+  }
+
+  private void provisionSnapshottableDirTrash(

Review comment:
       Return the trash path.




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

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


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

    Worklog Id:     (was: 492909)
    Time Spent: 0.5h  (was: 20m)

> Create trash dir when allowing snapshottable dir
> ------------------------------------------------
>
>                 Key: HDFS-15607
>                 URL: https://issues.apache.org/jira/browse/HDFS-15607
>             Project: Hadoop HDFS
>          Issue Type: Sub-task
>          Components: hdfs
>    Affects Versions: 3.4.0
>            Reporter: Siyao Meng
>            Assignee: Siyao Meng
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> In {{TrashPolicyDefault}}, the {{.Trash}} directory will be created with 
> permission 700 (and without sticky bit) by the first user that moves a file 
> to the trash. This is an issue when other users try to move files to that 
> trash because they may not have the permission to move to that trash if the 
> trash root is shared. -- in this case, snapshottable directories.
> This only affects users when trash is enabled inside snapshottable 
> directories ({{dfs.namenode.snapshot.trashroot.enabled}} set to true), and 
> when a user performing move to trash operations doesn't have admin 
> permissions.
> Solution: Create a {{.Trash}} directory with 777 permission and sticky bits 
> enabled (similar solution as HDFS-10324).
> Also need to deal with some corner cases:
> 1. even when the snapshottable directory trash root config is not enabled 
> ({{dfs.namenode.snapshot.trashroot.enabled}} set to false), create the 
> {{.Trash}} directory anyway? Or should we ask the admin to provision trash 
> manually after enabling {{dfs.namenode.snapshot.trashroot.enabled}} on an 
> existing cluster?
> - If the cluster is just upgraded, we need to provision trash manually anyway.
> 2. When immediately disallowing trash, it shouldn't fail. just remove the 
> .Trash directory when disallowing snapshot on a dir if it is empty?



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

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