Przeglądaj źródła

HADOOP-2634. Deprecate ClientProtocol::exists.
Contributed by lohit vijayarenu.



git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@644155 13f79535-47bb-0310-9956-ffa450edef68

Christopher Douglas 17 lat temu
rodzic
commit
57689de4ab

+ 3 - 0
CHANGES.txt

@@ -74,6 +74,9 @@ Trunk (unreleased changes)
     HADOOP-2839. Remove deprecated FileSystem::globPaths.
     HADOOP-2839. Remove deprecated FileSystem::globPaths.
     (lohit vijayarenu via cdouglas)
     (lohit vijayarenu via cdouglas)
 
 
+    HADOOP-2634. Deprecate ClientProtocol::exists.
+    (lohit vijayarenu via cdouglas)
+
   NEW FEATURES
   NEW FEATURES
 
 
     HADOOP-1398.  Add HBase in-memory block cache.  (tomwhite)
     HADOOP-1398.  Add HBase in-memory block cache.  (tomwhite)

+ 2 - 1
src/java/org/apache/hadoop/dfs/ClientProtocol.java

@@ -231,9 +231,10 @@ interface ClientProtocol extends VersionedProtocol {
    */
    */
   public boolean delete(String src, boolean recursive) throws IOException;
   public boolean delete(String src, boolean recursive) throws IOException;
   
   
-  /**
+  /** @deprecated Use getFileInfo() instead
    * Check whether the given file exists.
    * Check whether the given file exists.
    */
    */
+  @Deprecated
   public boolean exists(String src) throws IOException;
   public boolean exists(String src) throws IOException;
 
 
   /**
   /**

+ 6 - 2
src/java/org/apache/hadoop/dfs/DFSClient.java

@@ -504,11 +504,15 @@ class DFSClient implements FSConstants {
     return namenode.delete(src, recursive);
     return namenode.delete(src, recursive);
   }
   }
   
   
-  /**
+  /** Implemented using getFileInfo(src)
    */
    */
   public boolean exists(String src) throws IOException {
   public boolean exists(String src) throws IOException {
     checkOpen();
     checkOpen();
-    return namenode.exists(src);
+    try {
+      return getFileInfo(src) != null;
+    } catch (FileNotFoundException e) {
+      return false;
+    }
   }
   }
 
 
   /** @deprecated Use getFileStatus() instead */
   /** @deprecated Use getFileStatus() instead */

+ 0 - 4
src/java/org/apache/hadoop/dfs/DistributedFileSystem.java

@@ -180,10 +180,6 @@ public class DistributedFileSystem extends FileSystem {
    return dfs.delete(getPathName(f), recursive);
    return dfs.delete(getPathName(f), recursive);
   }
   }
   
   
-  public boolean exists(Path f) throws IOException {
-    return dfs.exists(getPathName(f));
-  }
-
   /** {@inheritDoc} */
   /** {@inheritDoc} */
   @Deprecated
   @Deprecated
   public long getContentLength(Path f) throws IOException {
   public long getContentLength(Path f) throws IOException {

+ 9 - 5
src/java/org/apache/hadoop/dfs/FSNamesystem.java

@@ -985,7 +985,7 @@ class FSNamesystem implements FSConstants, FSNamesystemMBean {
       throw new IOException("Invalid file name: " + src);      	  
       throw new IOException("Invalid file name: " + src);      	  
     }
     }
     if (isPermissionEnabled) {
     if (isPermissionEnabled) {
-      if (overwrite && exists(src)) {
+      if (overwrite && dir.exists(src)) {
         checkPathAccess(src, FsAction.WRITE);
         checkPathAccess(src, FsAction.WRITE);
       }
       }
       else {
       else {
@@ -1539,14 +1539,18 @@ class FSNamesystem implements FSConstants, FSNamesystemMBean {
     return true;
     return true;
   }
   }
 
 
-  /**
+  /** @deprecated Use getFileInfo(String) instead
    * Return whether the given filename exists
    * Return whether the given filename exists
    */
    */
+  @Deprecated
   public boolean exists(String src) throws AccessControlException {
   public boolean exists(String src) throws AccessControlException {
-    if (isPermissionEnabled) {
-      checkTraverse(src);
+    try {
+      getFileInfo(src);
+      return true;
+    } catch (IOException e) {
+      //getFileInfo throws IOException for file not found
+      return false;
     }
     }
-    return dir.exists(src);
   }
   }
 
 
   /** Get the file info for a specific file.
   /** Get the file info for a specific file.

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

@@ -208,12 +208,6 @@ public class HftpFileSystem extends FileSystem {
     }
     }
   }
   }
 
 
-  @Override
-  public boolean exists(Path f) throws IOException {
-    LsParser lsparser = new LsParser();
-    return lsparser.getFileStatus(f) != null;
-  }
-
   @Override
   @Override
   public FileStatus[] listStatus(Path f) throws IOException {
   public FileStatus[] listStatus(Path f) throws IOException {
     LsParser lsparser = new LsParser();
     LsParser lsparser = new LsParser();

+ 8 - 2
src/java/org/apache/hadoop/dfs/NameNode.java

@@ -382,10 +382,16 @@ public class NameNode implements ClientProtocol, DatanodeProtocol,
     stateChangeLog.debug("*DIR* Namenode.delete:  " + src);
     stateChangeLog.debug("*DIR* Namenode.delete:  " + src);
     return namesystem.delete(src, recursive);
     return namesystem.delete(src, recursive);
   }
   }
-  /**
+  /**@deprecated Use getFileInfo(String) instead
    */
    */
+  @Deprecated
   public boolean exists(String src) throws IOException {
   public boolean exists(String src) throws IOException {
-    return namesystem.exists(src);
+    try {
+      getFileInfo(src);
+      return true;
+    } catch (FileNotFoundException e) {
+      return false;
+    }
   }
   }
 
 
   /**
   /**

+ 7 - 1
src/java/org/apache/hadoop/fs/FileSystem.java

@@ -580,7 +580,13 @@ public abstract class FileSystem extends Configured implements Closeable {
   /** Check if exists.
   /** Check if exists.
    * @param f source file
    * @param f source file
    */
    */
-  public abstract boolean exists(Path f) throws IOException;
+  public boolean exists(Path f) throws IOException {
+    try {
+      return getFileStatus(f) != null;
+    } catch (FileNotFoundException e) {
+      return false;
+    }
+  }
 
 
   /** True iff the named path is a directory. */
   /** True iff the named path is a directory. */
   /** @deprecated Use getFileStatus() instead */ @Deprecated
   /** @deprecated Use getFileStatus() instead */ @Deprecated

+ 0 - 7
src/java/org/apache/hadoop/fs/FilterFileSystem.java

@@ -145,13 +145,6 @@ public class FilterFileSystem extends FileSystem {
     return fs.delete(f, recursive);
     return fs.delete(f, recursive);
   }
   }
   
   
-  /** Check if exists.
-   * @param f source file
-   */
-  public boolean exists(Path f) throws IOException {
-    return fs.exists(f);
-  }
-
   /** List files in a directory. */
   /** List files in a directory. */
   public FileStatus[] listStatus(Path f) throws IOException {
   public FileStatus[] listStatus(Path f) throws IOException {
     return fs.listStatus(f);
     return fs.listStatus(f);

+ 0 - 6
src/java/org/apache/hadoop/fs/InMemoryFileSystem.java

@@ -273,12 +273,6 @@ public class InMemoryFileSystem extends ChecksumFileSystem {
         return false;
         return false;
       }
       }
     }
     }
-
-    public boolean exists(Path f) throws IOException {
-      synchronized (this) {
-        return pathToFileAttribs.containsKey(getPath(f));
-      }
-    }
   
   
     /**
     /**
      * Directory operations are not supported
      * Directory operations are not supported

+ 1 - 5
src/java/org/apache/hadoop/fs/RawLocalFileSystem.java

@@ -226,11 +226,7 @@ public class RawLocalFileSystem extends FileSystem {
     }
     }
     return FileUtil.fullyDelete(f);
     return FileUtil.fullyDelete(f);
   }
   }
-  
-  public boolean exists(Path f) throws IOException {
-    return pathToFile(f).exists();
-  }
-
+ 
   public FileStatus[] listStatus(Path f) throws IOException {
   public FileStatus[] listStatus(Path f) throws IOException {
     File localf = pathToFile(f);
     File localf = pathToFile(f);
     FileStatus[] results;
     FileStatus[] results;

+ 0 - 7
src/java/org/apache/hadoop/fs/kfs/KosmosFileSystem.java

@@ -95,13 +95,6 @@ public class KosmosFileSystem extends FileSystem {
 	return new Path(workingDir, path);
 	return new Path(workingDir, path);
     }
     }
 
 
-    public boolean exists(Path path) throws IOException {
-	// stat the path to make sure it exists
-	Path absolute = makeAbsolute(path);
-        String srep = absolute.toUri().getPath();
-        return kfsImpl.exists(srep);
-    }
-
     public boolean mkdirs(Path path, FsPermission permission
     public boolean mkdirs(Path path, FsPermission permission
         ) throws IOException {
         ) throws IOException {
 	Path absolute = makeAbsolute(path);
 	Path absolute = makeAbsolute(path);

+ 0 - 5
src/java/org/apache/hadoop/fs/s3/S3FileSystem.java

@@ -125,11 +125,6 @@ public class S3FileSystem extends FileSystem {
     return new Path(workingDir, path);
     return new Path(workingDir, path);
   }
   }
 
 
-  @Override
-  public boolean exists(Path path) throws IOException {
-    return store.inodeExists(makeAbsolute(path));
-  }
-
   /**
   /**
    * @param permission Currently ignored.
    * @param permission Currently ignored.
    */
    */