Selaa lähdekoodia

HDFS-5533. Symlink delete/create should be treated as DELETE/CREATE in snapshot diff report. Contributed by Binglin Chang.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1545357 13f79535-47bb-0310-9956-ffa450edef68
Jing Zhao 11 vuotta sitten
vanhempi
commit
eb3c1607b0

+ 3 - 0
hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

@@ -612,6 +612,9 @@ Release 2.3.0 - UNRELEASED
     HDFS-5552. Fix wrong information of "Cluster summay" in dfshealth.html.
     (Haohui Mai via jing9)
 
+    HDFS-5533. Symlink delete/create should be treated as DELETE/CREATE in snapshot diff 
+    report. (Binglin Chang via jing9)
+
 Release 2.2.1 - UNRELEASED
 
   INCOMPATIBLE CHANGES

+ 4 - 8
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/snapshot/INodeDirectoryWithSnapshot.java

@@ -185,14 +185,10 @@ public class INodeDirectoryWithSnapshot extends INodeDirectoryWithQuota {
         INode dnode = deleted.get(d);
         if (cnode.compareTo(dnode.getLocalNameBytes()) == 0) {
           fullPath[fullPath.length - 1] = cnode.getLocalNameBytes();
-          if (cnode.isSymlink() && dnode.isSymlink()) {
-            dList.add(new DiffReportEntry(DiffType.MODIFY, fullPath));
-          } else {
-            // must be the case: delete first and then create an inode with the
-            // same name
-            cList.add(new DiffReportEntry(DiffType.CREATE, fullPath));
-            dList.add(new DiffReportEntry(DiffType.DELETE, fullPath));
-          }
+          // must be the case: delete first and then create an inode with the
+          // same name
+          cList.add(new DiffReportEntry(DiffType.CREATE, fullPath));
+          dList.add(new DiffReportEntry(DiffType.DELETE, fullPath));
           c++;
           d++;
         } else if (cnode.compareTo(dnode.getLocalNameBytes()) < 0) {

+ 26 - 3
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDiffReport.java

@@ -92,12 +92,15 @@ public class TestSnapshotDiffReport {
     Path file11 = new Path(modifyDir, "file11");
     Path file12 = new Path(modifyDir, "file12");
     Path file13 = new Path(modifyDir, "file13");
+    Path link13 = new Path(modifyDir, "link13");
     Path file14 = new Path(modifyDir, "file14");
     Path file15 = new Path(modifyDir, "file15");
     DFSTestUtil.createFile(hdfs, file10, BLOCKSIZE, REPLICATION_1, seed);
     DFSTestUtil.createFile(hdfs, file11, BLOCKSIZE, REPLICATION_1, seed);
     DFSTestUtil.createFile(hdfs, file12, BLOCKSIZE, REPLICATION_1, seed);
     DFSTestUtil.createFile(hdfs, file13, BLOCKSIZE, REPLICATION_1, seed);
+    // create link13
+    hdfs.createSymlink(file13, link13, false);
     // create snapshot
     for (Path snapshotDir : snapshotDirs) {
       hdfs.allowSnapshot(snapshotDir);
@@ -110,6 +113,8 @@ public class TestSnapshotDiffReport {
     hdfs.setReplication(file12, REPLICATION);
     // modify file13
     hdfs.setReplication(file13, REPLICATION);
+    // delete link13
+    hdfs.delete(link13, false);
     // create file14
     DFSTestUtil.createFile(hdfs, file14, BLOCKSIZE, REPLICATION, seed);
     // create file15
@@ -126,6 +131,8 @@ public class TestSnapshotDiffReport {
     hdfs.delete(file12, true);
     // modify file13
     hdfs.setReplication(file13, (short) (REPLICATION - 2));
+    // create link13 again
+    hdfs.createSymlink(file13, link13, false);
     // delete file14
     hdfs.delete(file14, true);
     // modify file15
@@ -222,7 +229,9 @@ public class TestSnapshotDiffReport {
         new DiffReportEntry(DiffType.DELETE, DFSUtil.string2Bytes("file12")),
         new DiffReportEntry(DiffType.DELETE, DFSUtil.string2Bytes("file11")),
         new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("file11")),
-        new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("file13")));
+        new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("file13")),
+        new DiffReportEntry(DiffType.DELETE, DFSUtil.string2Bytes("link13")),
+        new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("link13")));
 
     verifyDiffReport(sub1, "s0", "s5", 
         new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("")),
@@ -232,6 +241,8 @@ public class TestSnapshotDiffReport {
         new DiffReportEntry(DiffType.DELETE, DFSUtil.string2Bytes("file11")),
         new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("file11")),
         new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("file13")),
+        new DiffReportEntry(DiffType.DELETE, DFSUtil.string2Bytes("link13")),
+        new DiffReportEntry(DiffType.CREATE, DFSUtil.string2Bytes("link13")),
         new DiffReportEntry(DiffType.MODIFY,
             DFSUtil.string2Bytes("subsub1/subsubsub1")),
         new DiffReportEntry(DiffType.CREATE,
@@ -240,6 +251,8 @@ public class TestSnapshotDiffReport {
             DFSUtil.string2Bytes("subsub1/subsubsub1/file11")),
         new DiffReportEntry(DiffType.CREATE,
             DFSUtil.string2Bytes("subsub1/subsubsub1/file13")),
+        new DiffReportEntry(DiffType.CREATE,
+            DFSUtil.string2Bytes("subsub1/subsubsub1/link13")),
         new DiffReportEntry(DiffType.CREATE,
             DFSUtil.string2Bytes("subsub1/subsubsub1/file15")));
     
@@ -253,6 +266,8 @@ public class TestSnapshotDiffReport {
             DFSUtil.string2Bytes("subsub1/subsubsub1/file11")),
         new DiffReportEntry(DiffType.CREATE,
             DFSUtil.string2Bytes("subsub1/subsubsub1/file13")),
+        new DiffReportEntry(DiffType.CREATE,
+            DFSUtil.string2Bytes("subsub1/subsubsub1/link13")),
         new DiffReportEntry(DiffType.CREATE,
             DFSUtil.string2Bytes("subsub1/subsubsub1/file15")));
     
@@ -270,7 +285,11 @@ public class TestSnapshotDiffReport {
         new DiffReportEntry(DiffType.CREATE,
             DFSUtil.string2Bytes("subsub1/subsubsub1/file11")),
         new DiffReportEntry(DiffType.MODIFY,
-            DFSUtil.string2Bytes("subsub1/subsubsub1/file13")));
+            DFSUtil.string2Bytes("subsub1/subsubsub1/file13")),
+        new DiffReportEntry(DiffType.CREATE,
+            DFSUtil.string2Bytes("subsub1/subsubsub1/link13")),
+        new DiffReportEntry(DiffType.DELETE,
+            DFSUtil.string2Bytes("subsub1/subsubsub1/link13")));
   }
   
   /**
@@ -300,7 +319,11 @@ public class TestSnapshotDiffReport {
         new DiffReportEntry(DiffType.CREATE,
             DFSUtil.string2Bytes("subsub1/subsubsub1/file11")),
         new DiffReportEntry(DiffType.MODIFY,
-            DFSUtil.string2Bytes("subsub1/subsubsub1/file13")));
+            DFSUtil.string2Bytes("subsub1/subsubsub1/file13")),
+        new DiffReportEntry(DiffType.CREATE,
+            DFSUtil.string2Bytes("subsub1/subsubsub1/link13")),
+        new DiffReportEntry(DiffType.DELETE,
+            DFSUtil.string2Bytes("subsub1/subsubsub1/link13")));
     // check diff report between s0 and the current status
     verifyDiffReport(sub1, "s0", "", 
         new DiffReportEntry(DiffType.MODIFY, DFSUtil.string2Bytes("")),