hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s..@apache.org
Subject svn commit: r648047 - in /hadoop/core/trunk: ./ src/java/org/apache/hadoop/dfs/ src/test/org/apache/hadoop/dfs/
Date Mon, 14 Apr 2008 23:05:16 GMT
Author: shv
Date: Mon Apr 14 16:05:11 2008
New Revision: 648047

URL: http://svn.apache.org/viewvc?rev=648047&view=rev
Log:
HADOOP-3239. getFileInfo() returns null for non-existing files instead of throwing FileNotFoundException.
Contributed by Lohit Vijayarenu.

Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/java/org/apache/hadoop/dfs/ClientProtocol.java
    hadoop/core/trunk/src/java/org/apache/hadoop/dfs/DFSClient.java
    hadoop/core/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java
    hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java
    hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java
    hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FileDataServlet.java
    hadoop/core/trunk/src/java/org/apache/hadoop/dfs/ListPathsServlet.java
    hadoop/core/trunk/src/java/org/apache/hadoop/dfs/NameNode.java
    hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestFileStatus.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=648047&r1=648046&r2=648047&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Mon Apr 14 16:05:11 2008
@@ -106,6 +106,9 @@
     HADOOP-2826. Deprecated FileSplit.getFile(), LineRecordReader.readLine().
     (Amareshwari Sriramadasu via ddas)
 
+    HADOOP-3239. getFileInfo() returns null for non-existing files instead
+    of throwing FileNotFoundException. (Lohit Vijayarenu via shv)
+
   NEW FEATURES
 
     HADOOP-1398.  Add HBase in-memory block cache.  (tomwhite)

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/dfs/ClientProtocol.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/dfs/ClientProtocol.java?rev=648047&r1=648046&r2=648047&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/dfs/ClientProtocol.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/dfs/ClientProtocol.java Mon Apr 14 16:05:11
2008
@@ -37,9 +37,9 @@
    * Compared to the previous version the following changes have been introduced:
    * (Only the latest change is reflected.
    * The log of historical changes can be retrieved from the svn).
-   * 28 : rollEditLog() returns CheckpointSignature instead of long.
+   * 29 : getFileInfo returns null instead of throwing FileNotFoundException
    */
-  public static final long versionID = 28L;
+  public static final long versionID = 29L;
   
   ///////////////////////////////////////
   // File contents
@@ -419,8 +419,9 @@
   /**
    * Get the file info for a specific file or directory.
    * @param src The string representation of the path to the file
-   * @throws IOException if file does not exist
+   * @throws IOException if permission to access file is denied by the system 
    * @return object containing information regarding the file
+   *         or null if file not found
    */
   public DFSFileInfo getFileInfo(String src) throws IOException;
 

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/dfs/DFSClient.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/dfs/DFSClient.java?rev=648047&r1=648046&r2=648047&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/dfs/DFSClient.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/dfs/DFSClient.java Mon Apr 14 16:05:11 2008
@@ -542,21 +542,17 @@
    */
   public boolean exists(String src) throws IOException {
     checkOpen();
-    try {
-      return getFileInfo(src) != null;
-    } catch (FileNotFoundException e) {
-      return false;
-    }
+    return getFileInfo(src) != null;
   }
 
   /** @deprecated Use getFileStatus() instead */
   @Deprecated
   public boolean isDirectory(String src) throws IOException {
-    try {
-      return getFileInfo(src).isDir();
-    } catch (FileNotFoundException e) {
-      return false;               // f does not exist
-    }
+    FileStatus fs = getFileInfo(src);
+    if (fs != null)
+      return fs.isDir();
+    else
+      throw new FileNotFoundException("File does not exist: " + src);
   }
 
   /**
@@ -575,8 +571,7 @@
     try {
       return namenode.getFileInfo(src);
     } catch(RemoteException re) {
-      throw re.unwrapRemoteException(AccessControlException.class,
-                                     FileNotFoundException.class);
+      throw re.unwrapRemoteException(AccessControlException.class);
     }
   }
 

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=648047&r1=648046&r2=648047&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 Mon Apr 14
16:05:11 2008
@@ -362,8 +362,11 @@
       DfsPath p = (DfsPath) f;
       return p.info;
     }
-    
-    return dfs.getFileInfo(getPathName(f));
+    FileStatus fs = dfs.getFileInfo(getPathName(f));
+    if (fs != null)
+      return fs;
+    else
+      throw new FileNotFoundException("File does not exist: " + f);
   }
 
   /** {@inheritDoc }*/

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java?rev=648047&r1=648046&r2=648047&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSDirectory.java Mon Apr 14 16:05:11
2008
@@ -573,17 +573,17 @@
     }
   }
 
-  /* Get the file info for a specific file.
+  /** Get the file info for a specific file.
    * @param src The string representation of the path to the file
-   * @throws IOException if file does not exist
    * @return object containing information regarding the file
+   *         or null if file not found
    */
-  DFSFileInfo getFileInfo(String src) throws FileNotFoundException {
+  DFSFileInfo getFileInfo(String src) {
     String srcs = normalizePath(src);
     synchronized (rootDir) {
       INode targetNode = rootDir.getNode(srcs);
       if (targetNode == null) {
-        throw new FileNotFoundException("File does not exist: " + srcs);
+        return null;
       }
       else {
         return new DFSFileInfo(srcs, targetNode);

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java?rev=648047&r1=648046&r2=648047&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FSNamesystem.java Mon Apr 14 16:05:11
2008
@@ -1536,20 +1536,15 @@
    * Return whether the given filename exists
    */
   @Deprecated
-  public boolean exists(String src) throws AccessControlException {
-    try {
-      getFileInfo(src);
-      return true;
-    } catch (IOException e) {
-      //getFileInfo throws IOException for file not found
-      return false;
-    }
+  public boolean exists(String src) throws IOException {
+      return getFileInfo(src) != null;
   }
 
   /** Get the file info for a specific file.
    * @param src The string representation of the path to the file
-   * @throws IOException if file does not exist
+   * @throws IOException if permission to access file is denied by the system 
    * @return object containing information regarding the file
+   *         or null if file not found
    */
   DFSFileInfo getFileInfo(String src) throws IOException {
     if (isPermissionEnabled) {

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FileDataServlet.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FileDataServlet.java?rev=648047&r1=648046&r2=648047&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FileDataServlet.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/dfs/FileDataServlet.java Mon Apr 14 16:05:11
2008
@@ -85,9 +85,11 @@
       final String path = request.getPathInfo() != null
         ? request.getPathInfo() : "/";
       DFSFileInfo info = nnproxy.getFileInfo(path);
-      if (!info.isDir()) {
+      if ((info != null) && !info.isDir()) {
         response.sendRedirect(createUri(info, ugi, nnproxy,
               request.getScheme()).toURL().toString());
+      } else if (info == null){
+        response.sendError(400, "cat: File not found " + path);
       } else {
         response.sendError(400, "cat: " + path + ": is a directory");
       }

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/dfs/ListPathsServlet.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/dfs/ListPathsServlet.java?rev=648047&r1=648046&r2=648047&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/dfs/ListPathsServlet.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/dfs/ListPathsServlet.java Mon Apr 14 16:05:11
2008
@@ -134,7 +134,7 @@
       }
 
       DFSFileInfo base = nnproxy.getFileInfo(path);
-      if (base.isDir()) {
+      if ((base != null) && base.isDir()) {
         writeInfo(base, doc);
       }
 

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/dfs/NameNode.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/dfs/NameNode.java?rev=648047&r1=648046&r2=648047&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/dfs/NameNode.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/dfs/NameNode.java Mon Apr 14 16:05:11 2008
@@ -386,12 +386,7 @@
    */
   @Deprecated
   public boolean exists(String src) throws IOException {
-    try {
-      getFileInfo(src);
-      return true;
-    } catch (FileNotFoundException e) {
-      return false;
-    }
+    return getFileInfo(src) != null;
   }
 
   /**
@@ -437,8 +432,9 @@
   /**
    * Get the file info for a specific file.
    * @param src The string representation of the path to the file
-   * @throws IOException if file does not exist
+   * @throws IOException if permission to access file is denied by the system
    * @return object containing information regarding the file
+   *         or null if file not found
    */
   public DFSFileInfo getFileInfo(String src)  throws IOException {
     return namesystem.getFileInfo(src);

Modified: hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestFileStatus.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestFileStatus.java?rev=648047&r1=648046&r2=648047&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestFileStatus.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestFileStatus.java Mon Apr 14 16:05:11
2008
@@ -82,6 +82,7 @@
     Configuration conf = new Configuration();
     MiniDFSCluster cluster = new MiniDFSCluster(conf, 1, true, null);
     FileSystem fs = cluster.getFileSystem();
+    DFSClient dfsClient = new DFSClient(conf);
     try {
 
       //
@@ -94,6 +95,10 @@
       assertTrue("/ should be a directory", 
                  fs.getFileStatus(path).isDir() == true);
       
+      // make sure getFileInfo returns null for files which do not exist
+      DFSFileInfo fileInfo = dfsClient.getFileInfo("/noSuchFile");
+      assertTrue(fileInfo == null);
+
       // create a file in home directory
       //
       Path file1 = new Path("filestatus.dat");



Mime
View raw message