You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-commits@hadoop.apache.org by su...@apache.org on 2009/10/16 00:48:41 UTC

svn commit: r825692 - in /hadoop/hdfs/branches/branch-0.21: ./ src/java/org/apache/hadoop/hdfs/server/namenode/ src/test/hdfs/org/apache/hadoop/fs/ src/test/hdfs/org/apache/hadoop/hdfs/

Author: suresh
Date: Thu Oct 15 22:48:40 2009
New Revision: 825692

URL: http://svn.apache.org/viewvc?rev=825692&view=rev
Log:
HDFS-709. Merging revision 825689 from trunk. Contributed by Suresh Srinivas.

Modified:
    hadoop/hdfs/branches/branch-0.21/CHANGES.txt
    hadoop/hdfs/branches/branch-0.21/src/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java
    hadoop/hdfs/branches/branch-0.21/src/test/hdfs/org/apache/hadoop/fs/TestHDFSFileContextMainOperations.java
    hadoop/hdfs/branches/branch-0.21/src/test/hdfs/org/apache/hadoop/hdfs/TestDFSRename.java

Modified: hadoop/hdfs/branches/branch-0.21/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hdfs/branches/branch-0.21/CHANGES.txt?rev=825692&r1=825691&r2=825692&view=diff
==============================================================================
--- hadoop/hdfs/branches/branch-0.21/CHANGES.txt (original)
+++ hadoop/hdfs/branches/branch-0.21/CHANGES.txt Thu Oct 15 22:48:40 2009
@@ -415,3 +415,6 @@
 
     HDFS-677. Rename failure when both source and destination quota exceeds
     results in deletion of source. (suresh)
+
+    HDFS-709. Fix TestDFSShell failure due to rename bug introduced by 
+    HDFS-677. (suresh)

Modified: hadoop/hdfs/branches/branch-0.21/src/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/branches/branch-0.21/src/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java?rev=825692&r1=825691&r2=825692&view=diff
==============================================================================
--- hadoop/hdfs/branches/branch-0.21/src/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java (original)
+++ hadoop/hdfs/branches/branch-0.21/src/java/org/apache/hadoop/hdfs/server/namenode/FSDirectory.java Thu Oct 15 22:48:40 2009
@@ -413,7 +413,9 @@
       if (dst.equals(src)) {
         return true;
       }
-      if (dst.startsWith(src)) {
+      // dst cannot be directory or a file under src
+      if (dst.startsWith(src) && 
+          dst.charAt(src.length()) == Path.SEPARATOR_CHAR) {
         NameNode.stateChangeLog.warn("DIR* FSDirectory.unprotectedRenameTo: "
             + "failed to rename " + src + " to " + dst
             + " because destination starts with src");

Modified: hadoop/hdfs/branches/branch-0.21/src/test/hdfs/org/apache/hadoop/fs/TestHDFSFileContextMainOperations.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/branches/branch-0.21/src/test/hdfs/org/apache/hadoop/fs/TestHDFSFileContextMainOperations.java?rev=825692&r1=825691&r2=825692&view=diff
==============================================================================
--- hadoop/hdfs/branches/branch-0.21/src/test/hdfs/org/apache/hadoop/fs/TestHDFSFileContextMainOperations.java (original)
+++ hadoop/hdfs/branches/branch-0.21/src/test/hdfs/org/apache/hadoop/fs/TestHDFSFileContextMainOperations.java Thu Oct 15 22:48:40 2009
@@ -92,15 +92,20 @@
     fs.setQuota(dst1.getParent(), FSConstants.QUOTA_DONT_SET,
         FSConstants.QUOTA_DONT_SET);
 
-    // Test1: src does not exceed quota and dst has quota to accommodate rename
+    // Test1: src does not exceed quota and dst has no quota check and hence 
+    // accommodates rename
     rename(src1, dst1, true, false);
 
     // Test2: src does not exceed quota and dst has *no* quota to accommodate
-    // rename
+    // rename. 
+
+    // testRenameWithQuota/dstDir now has quota = 1 and dst1 already uses it
     fs.setQuota(dst1.getParent(), 1, FSConstants.QUOTA_DONT_SET);
     rename(src2, dst2, false, true);
 
     // Test3: src exceeds quota and dst has *no* quota to accommodate rename
+    
+    // src1 has no quota to accommodate new rename node
     fs.setQuota(src1.getParent(), 1, FSConstants.QUOTA_DONT_SET);
     rename(dst1, src1, false, true);
   }

Modified: hadoop/hdfs/branches/branch-0.21/src/test/hdfs/org/apache/hadoop/hdfs/TestDFSRename.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/branches/branch-0.21/src/test/hdfs/org/apache/hadoop/hdfs/TestDFSRename.java?rev=825692&r1=825691&r2=825692&view=diff
==============================================================================
--- hadoop/hdfs/branches/branch-0.21/src/test/hdfs/org/apache/hadoop/hdfs/TestDFSRename.java (original)
+++ hadoop/hdfs/branches/branch-0.21/src/test/hdfs/org/apache/hadoop/hdfs/TestDFSRename.java Thu Oct 15 22:48:40 2009
@@ -38,6 +38,12 @@
     }
   }
 
+  static void createFile(FileSystem fs, Path f) throws IOException {
+    DataOutputStream a_out = fs.create(f);
+    a_out.writeBytes("something");
+    a_out.close();
+  }
+  
   public void testRename() throws Exception {
     Configuration conf = new HdfsConfiguration();
     MiniDFSCluster cluster = new MiniDFSCluster(conf, 2, true, null);
@@ -50,9 +56,7 @@
         Path aa = new Path(dir, "aa");
         Path b = new Path(dir, "b");
   
-        DataOutputStream a_out = fs.create(a);
-        a_out.writeBytes("something");
-        a_out.close();
+        createFile(fs, a);
         
         //should not have any lease
         assertEquals(0, countLease(cluster)); 
@@ -78,26 +82,37 @@
         assertFalse(fs.exists(dstPath));
         assertFalse(fs.rename(dir, dstPath));
       }
-
-      { // test rename /a/b to /a/b/c
+      
+      { // dst cannot be a file or directory under src
+        // test rename /a/b/foo to /a/b/c
         Path src = new Path("/a/b");
         Path dst = new Path("/a/b/c");
 
-        DataOutputStream a_out = fs.create(new Path(src, "foo"));
-        a_out.writeBytes("something");
-        a_out.close();
+        createFile(fs, new Path(src, "foo"));
+        
+        // dst cannot be a file under src
+        assertFalse(fs.rename(src, dst)); 
         
-        assertFalse(fs.rename(src, dst));
+        // dst cannot be a directory under src
+        assertFalse(fs.rename(src.getParent(), dst.getParent())); 
       }
       
-      { // test rename /a/b/c to /a/b/c
+      { // dst can start with src, if it is not a directory or file under src
+        // test rename /test /testfile
+        Path src = new Path("/testPrefix");
+        Path dst = new Path("/testPrefixfile");
+
+        createFile(fs, src);
+        assertTrue(fs.rename(src, dst));
+      }
+      
+      { // dst should not be same as src test rename /a/b/c to /a/b/c
         Path src = new Path("/a/b/c");
-        DataOutputStream a_out = fs.create(src);
-        a_out.writeBytes("something");
-        a_out.close();
+        createFile(fs, src);
         assertTrue(fs.rename(src, src));
+        assertFalse(fs.rename(new Path("/a/b"), new Path("/a/b/")));
+        assertTrue(fs.rename(src, new Path("/a/b/c/")));
       }
-      
       fs.delete(dir, true);
     } finally {
       if (cluster != null) {cluster.shutdown();}