Explorar o código

HADOOP-9761. ViewFileSystem#rename fails when using DistributedFileSystem. (Andrew Wang via Colin Patrick McCabe)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2.1-beta@1526290 13f79535-47bb-0310-9956-ffa450edef68
Andrew Wang %!s(int64=11) %!d(string=hai) anos
pai
achega
0b1d3f8af5

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

@@ -27,6 +27,9 @@ Release 2.1.2 - UNRELEASED
     HADOOP-9776. HarFileSystem.listStatus() returns invalid authority if port
     number is empty. (Shanyu Zhao via ivanmi)
 
+    HADOOP-9761.  ViewFileSystem#rename fails when using DistributedFileSystem.
+    (Andrew Wang via Colin Patrick McCabe)
+
 Release 2.1.1-beta - 2013-09-23
 
   INCOMPATIBLE CHANGES

+ 3 - 1
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystemLinkResolver.java

@@ -72,7 +72,9 @@ public abstract class FileSystemLinkResolver<T> {
     int count = 0;
     T in = null;
     Path p = path;
-    FileSystem fs = FileSystem.getFSofPath(p, filesys.getConf());
+    // Assumes path belongs to this FileSystem.
+    // Callers validate this by passing paths through FileSystem#checkPath
+    FileSystem fs = filesys;
     for (boolean isLink = true; isLink;) {
       try {
         in = doCall(p);

+ 9 - 21
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DistributedFileSystem.java

@@ -170,12 +170,11 @@ public class DistributedFileSystem extends FileSystem {
   }
 
   /**
-   * Checks that the passed URI belongs to this filesystem, resolves the path
-   * component against the current working directory if relative, and finally
-   * returns the absolute path component.
+   * Checks that the passed URI belongs to this filesystem and returns
+   * just the path component. Expects a URI with an absolute path.
    * 
-   * @param file URI to check and resolve
-   * @return resolved absolute path component of {file}
+   * @param file URI with absolute path
+   * @return path component of {file}
    * @throws IllegalArgumentException if URI does not belong to this DFS
    */
   private String getPathName(Path file) {
@@ -514,15 +513,10 @@ public class DistributedFileSystem extends FileSystem {
   @Override
   public boolean rename(Path src, Path dst) throws IOException {
     statistics.incrementWriteOps(1);
-    // Both Paths have to belong to this DFS
+
     final Path absSrc = fixRelativePart(src);
     final Path absDst = fixRelativePart(dst);
-    FileSystem srcFS = getFSofPath(absSrc, getConf());
-    FileSystem dstFS = getFSofPath(absDst, getConf());
-    if (!srcFS.getUri().equals(getUri()) ||
-        !dstFS.getUri().equals(getUri())) {
-      throw new IOException("Renames across FileSystems not supported");
-    }
+
     // Try the rename without resolving first
     try {
       return dfs.rename(getPathName(absSrc), getPathName(absDst));
@@ -539,7 +533,8 @@ public class DistributedFileSystem extends FileSystem {
         @Override
         public Boolean next(final FileSystem fs, final Path p)
             throws IOException {
-          return fs.rename(source, p);
+          // Should just throw an error in FileSystem#checkPath
+          return doCall(p);
         }
       }.resolve(this, absDst);
     }
@@ -553,15 +548,8 @@ public class DistributedFileSystem extends FileSystem {
   public void rename(Path src, Path dst, final Options.Rename... options)
       throws IOException {
     statistics.incrementWriteOps(1);
-    // Both Paths have to belong to this DFS
     final Path absSrc = fixRelativePart(src);
     final Path absDst = fixRelativePart(dst);
-    FileSystem srcFS = getFSofPath(absSrc, getConf());
-    FileSystem dstFS = getFSofPath(absDst, getConf());
-    if (!srcFS.getUri().equals(getUri()) ||
-        !dstFS.getUri().equals(getUri())) {
-      throw new IOException("Renames across FileSystems not supported");
-    }
     // Try the rename without resolving first
     try {
       dfs.rename(getPathName(absSrc), getPathName(absDst), options);
@@ -579,7 +567,7 @@ public class DistributedFileSystem extends FileSystem {
         @Override
         public Void next(final FileSystem fs, final Path p)
             throws IOException {
-          // Since we know it's this DFS for both, can just call doCall again
+          // Should just throw an error in FileSystem#checkPath
           return doCall(p);
         }
       }.resolve(this, absDst);

+ 7 - 1
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemHdfs.java

@@ -24,8 +24,10 @@ import java.net.URISyntaxException;
 import javax.security.auth.login.LoginException;
 
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.CommonConfigurationKeys;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.FileSystemTestHelper;
+import org.apache.hadoop.fs.FsConstants;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.hdfs.DFSConfigKeys;
 import org.apache.hadoop.hdfs.MiniDFSCluster;
@@ -69,7 +71,11 @@ public class TestViewFileSystemHdfs extends ViewFileSystemBaseTest {
     
     fHdfs = cluster.getFileSystem(0);
     fHdfs2 = cluster.getFileSystem(1);
-    
+    fHdfs.getConf().set(CommonConfigurationKeys.FS_DEFAULT_NAME_KEY,
+        FsConstants.VIEWFS_URI.toString());
+    fHdfs2.getConf().set(CommonConfigurationKeys.FS_DEFAULT_NAME_KEY,
+        FsConstants.VIEWFS_URI.toString());
+
     defaultWorkingDirectory = fHdfs.makeQualified( new Path("/user/" + 
         UserGroupInformation.getCurrentUser().getShortUserName()));
     defaultWorkingDirectory2 = fHdfs2.makeQualified( new Path("/user/" +