zhjwpku commented on a change in pull request #1670: HDFS-14925. Rename 
operation should check nest snapshot
URL: https://github.com/apache/hadoop/pull/1670#discussion_r339302713
 
 

 ##########
 File path: 
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirRenameOp.java
 ##########
 @@ -574,7 +580,28 @@ private static void validateRenameSource(FSDirectory fsd,
     }
     // srcInode and its subtree cannot contain snapshottable directories with
     // snapshots
-    FSDirSnapshotOp.checkSnapshot(fsd, srcIIP, null);
+    FSDirSnapshotOp.checkSnapshot(fsd, srcIIP, snapshottableDirs);
+  }
+
+  private static void validateNestSnapshot(FSDirectory fsd, INodeDirectory 
dstParent,
+      List<INodeDirectory> snapshottableDirs) throws SnapshotException {
+
+    if (fsd.getFSNamesystem().getSnapshotManager().isAllowNestedSnapshots()) {
+      return;
+    }
+
+    /*
+     * snapshottableDirs is a list of snapshottable directory(child of rename 
src)
+     * which do not have snapshots yet. If this list is not empty, that means 
rename
+     * src have snapshottable descendant directories.
+     */
+    if (snapshottableDirs != null && snapshottableDirs.size() > 0) {
+      if 
(fsd.getFSNamesystem().getSnapshotManager().isDescendantOfSnapshotRoot(dstParent))
 {
+        String fullPath = dstParent.getFullPathName();
+        throw new SnapshotException("Failed to rename to " + fullPath +
+                " due to nested snapshottable directory");
 
 Review comment:
   I will polish this exception msg, and add a unit test, thx.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

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

Reply via email to