Преглед на файлове

Merge -r 666055:666056 from trunk to 0.18 branch. Fixes: HADOOP-3519.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.18@666057 13f79535-47bb-0310-9956-ffa450edef68
Thomas White преди 17 години
родител
ревизия
f7d501f86b

+ 2 - 0
CHANGES.txt

@@ -547,6 +547,8 @@ Release 0.18.0 - Unreleased
 
     HADOOP-3513. Improve NNThroughputBenchmark log messages. (shv)
 
+    HADOOP-3519.  Fix NPE in DFS FileSystem rename.  (hairong via tomwhite)
+
 Release 0.17.0 - 2008-05-18
 
   INCOMPATIBLE CHANGES

+ 9 - 3
src/hdfs/org/apache/hadoop/dfs/FSDirectory.java

@@ -363,10 +363,16 @@ class FSDirectory implements FSConstants, Closeable {
       INode[] dstInodes = new INode[dstComponents.length];
       rootDir.getExistingPathINodes(dstComponents, dstInodes);
       
-      // check the existence of the destination
-      if (dstInodes[dstInodes.length-1] != null) {
+      // check the validity of the destination
+      if (dstInodes[dstInodes.length-1] != null) { //check if destination exists
         NameNode.stateChangeLog.warn("DIR* FSDirectory.unprotectedRenameTo: "
-                                     +"failed to rename "+src+" to "+dst+ " because destination exists");
+                                     +"failed to rename "+src+" to "+dst+ 
+                                     " because destination exists");
+        return false;
+      } else if (dstInodes[dstInodes.length-2] == null) { // check if its parent exists
+        NameNode.stateChangeLog.warn("DIR* FSDirectory.unprotectedRenameTo: "
+            +"failed to rename "+src+" to "+dst+ 
+            " because destination's parent does not exists");
         return false;
       }
       

+ 5 - 0
src/test/org/apache/hadoop/dfs/TestDFSRename.java

@@ -71,6 +71,11 @@ public class TestDFSRename extends junit.framework.TestCase {
       //should not have any lease
       assertEquals(0, countLease(cluster)); 
 
+      // test non-existent destination
+      Path dstPath = new Path("/c/d");
+      assertFalse(fs.exists(dstPath));
+      assertFalse(fs.rename(dir, dstPath));
+      
       fs.delete(dir, true);
     } finally {
       if (cluster != null) {cluster.shutdown();}

+ 0 - 6
src/test/org/apache/hadoop/dfs/TestHDFSFileSystemContract.java

@@ -38,10 +38,4 @@ public class TestHDFSFileSystemContract extends FileSystemContractBaseTest {
     cluster.shutdown();
   }
   
-  @Override
-  protected boolean renameSupported() {
-    // disable for the moment as rename tests are not working on HDFS yet
-    return false;
-  }
-
 }