hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r632403 - in /hadoop/core/trunk: CHANGES.txt src/java/org/apache/hadoop/dfs/DistributedFileSystem.java src/java/org/apache/hadoop/fs/FileSystem.java src/test/org/apache/hadoop/dfs/TestDFSShell.java
Date Fri, 29 Feb 2008 18:36:37 GMT
Author: cutting
Date: Fri Feb 29 10:36:24 2008
New Revision: 632403

URL: http://svn.apache.org/viewvc?rev=632403&view=rev
Log:
HADOOP-1967.  Use authority from default filesystem when none specified.

Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java
    hadoop/core/trunk/src/java/org/apache/hadoop/fs/FileSystem.java
    hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestDFSShell.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=632403&r1=632402&r2=632403&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Fri Feb 29 10:36:24 2008
@@ -41,6 +41,12 @@
     presence of snapshots. Needed for supporting appends to HDFS
     files. (dhruba) 
 
+    HADOOP-1967.  When a Path specifies the same scheme as the default
+    FileSystem but no authority, the default FileSystem's authority is
+    used.  Also add warnings for old-format FileSystem names, accessor
+    methods for fs.default.name, and check for null authority in HDFS.
+    (cutting)
+
   OPTIMIZATIONS
 
   BUG FIXES

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java?rev=632403&r1=632402&r2=632403&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java Fri Feb 29
10:36:24 2008
@@ -63,6 +63,9 @@
     setConf(conf);
     String host = uri.getHost();
     int port = uri.getPort();
+    if (host == null || port == -1) {
+      throw new IOException("Incomplete HDFS URI, no host/port: "+ uri);
+    }
     this.dfs = new DFSClient(new InetSocketAddress(host, port), conf);
     this.uri = URI.create("hdfs://"+host+":"+port);
     this.workingDir = getHomeDirectory();

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/fs/FileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/fs/FileSystem.java?rev=632403&r1=632402&r2=632403&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/fs/FileSystem.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/fs/FileSystem.java Fri Feb 29 10:36:24 2008
@@ -51,6 +51,8 @@
  * implementation is {@link DistributedFileSystem}.
  *****************************************************************/
 public abstract class FileSystem extends Configured {
+  private static final String FS_DEFAULT_NAME_KEY = "fs.default.name";
+
   public static final Log LOG = LogFactory.getLog("org.apache.hadoop.fs.FileSystem");
 
   // cache indexed by URI scheme and authority
@@ -91,7 +93,31 @@
 
   /** Returns the configured filesystem implementation.*/
   public static FileSystem get(Configuration conf) throws IOException {
-    return getNamed(conf.get("fs.default.name", "file:///"), conf);
+    return get(getDefaultUri(conf), conf);
+  }
+  
+  /** Get the default filesystem URI from a configuration.
+   * @param conf the configuration to access
+   * @return the uri of the default filesystem
+   */
+  public static URI getDefaultUri(Configuration conf) {
+    return URI.create(fixName(conf.get(FS_DEFAULT_NAME_KEY, "file:///")));
+  }
+
+  /** Set the default filesystem URI in a configuration.
+   * @param conf the configuration to alter
+   * @param uri the new default filesystem uri
+   */
+  public static void setDefaultUri(Configuration conf, URI uri) {
+    conf.set(FS_DEFAULT_NAME_KEY, uri.toString());
+  }
+
+  /** Set the default filesystem URI in a configuration.
+   * @param conf the configuration to alter
+   * @param uri the new default filesystem uri
+   */
+  public static void setDefaultUri(Configuration conf, String uri) {
+    setDefaultUri(conf, URI.create(fixName(uri)));
   }
 
   /** Called after a new FileSystem instance is constructed.
@@ -111,15 +137,24 @@
   /** @deprecated call #get(URI,Configuration) instead. */
   public static FileSystem getNamed(String name, Configuration conf)
     throws IOException {
+    return get(URI.create(fixName(name)), conf);
+  }
 
+  /** Update old-format filesystem names, for back-compatibility.  This should
+   * eventually be replaced with a checkName() method that throws an exception
+   * for old-format names. */ 
+  private static String fixName(String name) {
     // convert old-format name to new-format name
     if (name.equals("local")) {         // "local" is now "file:///".
+      LOG.warn("\"local\" is a deprecated filesystem name."
+               +" Use \"file:///\" instead.");
       name = "file:///";
     } else if (name.indexOf('/')==-1) {   // unqualified is "hdfs://"
+      LOG.warn("\""+name+"\" is a deprecated filesystem name."
+               +" Use \"hdfs://"+name+"/\" instead.");
       name = "hdfs://"+name;
     }
-
-    return get(URI.create(name), conf);
+    return name;
   }
 
   /**
@@ -147,6 +182,14 @@
       return get(conf);
     }
 
+    if (authority == null) {                       // no authority
+      URI defaultUri = getDefaultUri(conf);
+      if (scheme.equals(defaultUri.getScheme())    // if scheme matches default
+          && defaultUri.getAuthority() != null) {  // & default has authority
+        return get(defaultUri, conf);              // return default
+      }
+    }
+
     Map<String,FileSystem> authorityToFs = CACHE.get(scheme);
     if (authorityToFs == null) {
       if (CACHE.isEmpty()) {
@@ -260,11 +303,22 @@
     URI uri = path.toUri();
     if (uri.getScheme() == null)                // fs is relative 
       return;
+    String thisScheme = this.getUri().getScheme();
+    String thatScheme = uri.getScheme();
     String thisAuthority = this.getUri().getAuthority();
     String thatAuthority = uri.getAuthority();
-    if (!(this.getUri().getScheme().equals(uri.getScheme()) &&
-           (thisAuthority == thatAuthority || 
-             (thisAuthority != null && thisAuthority.equals(thatAuthority))))){
+    if (thisScheme.equals(thatScheme)) {          // schemes match
+      if (thisAuthority == thatAuthority ||       // & authorities match
+          (thisAuthority != null && thisAuthority.equals(thatAuthority)))
+        return;
+
+      if (thatAuthority == null &&                // path's authority is null
+          thisAuthority != null) {                // fs has an authority
+        URI defaultUri = getDefaultUri(getConf()); // & is the default fs
+        if (thisScheme.equals(defaultUri.getScheme()) &&
+            thisAuthority.equals(defaultUri.getAuthority()))
+          return;
+      }
       throw new IllegalArgumentException("Wrong FS: "+path+
                                          ", expected: "+this.getUri());
     }

Modified: hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestDFSShell.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestDFSShell.java?rev=632403&r1=632402&r2=632403&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestDFSShell.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestDFSShell.java Fri Feb 29 10:36:24
2008
@@ -382,6 +382,19 @@
       confirmOwner(null, "herbivores", dstFs, parent, path);
       runCmd(shell, "-chown", "-R", ":reptiles", dstFs.getUri().toString() + "/");
       confirmOwner(null, "reptiles", dstFs, root, parent, path);
+      //check if default hdfs:/// works 
+      argv[0] = "-cat";
+      argv[1] = "hdfs:///furi";
+      ret = ToolRunner.run(shell, argv);
+      assertTrue(" default works for cat", (ret == 0));
+      argv[0] = "-ls";
+      argv[1] = "hdfs:///";
+      ret = ToolRunner.run(shell, argv);
+      assertTrue("default works for ls ", (ret == 0));
+      argv[0] = "-rmr";
+      argv[1] = "hdfs:///furi";
+      ret = ToolRunner.run(shell, argv);
+      assertTrue("default works for rm/rmr", (ret ==0));
     } finally {
       System.setProperty("test.build.data", bak);
       if (null != srcCluster) {



Mime
View raw message