From a4d4a23785356e6a19d0db3a2dec8ae8cf861273 Mon Sep 17 00:00:00 2001 From: Mingliang Liu Date: Thu, 16 Feb 2017 16:25:51 -0800 Subject: [PATCH] HADOOP-13321. Deprecate FileSystem APIs that promote inefficient call patterns. Contributed by Chris Nauroth and Mingliang Liu --- .../java/org/apache/hadoop/fs/ChecksumFileSystem.java | 2 ++ .../main/java/org/apache/hadoop/fs/FileSystem.java | 11 +++++++++++ .../java/org/apache/hadoop/fs/ftp/FTPFileSystem.java | 1 + .../java/org/apache/hadoop/fs/s3a/S3AFileSystem.java | 2 ++ .../fs/swift/snative/SwiftNativeFileSystem.java | 2 ++ 5 files changed, 18 insertions(+) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFileSystem.java index e0ce327a0f..14c190553a 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ChecksumFileSystem.java @@ -605,6 +605,7 @@ boolean apply(Path p) throws IOException { * Rename files/dirs */ @Override + @SuppressWarnings("deprecation") public boolean rename(Path src, Path dst) throws IOException { if (fs.isDirectory(src)) { return fs.rename(src, dst); @@ -721,6 +722,7 @@ public void copyToLocalFile(boolean delSrc, Path src, Path dst) * If src and dst are directories, the copyCrc parameter * determines whether to copy CRC files. */ + @SuppressWarnings("deprecation") public void copyToLocalFile(Path src, Path dst, boolean copyCrc) throws IOException { if (!fs.isDirectory(src)) { // source is a file diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java index 55cd97e643..ededfa9810 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java @@ -1624,6 +1624,11 @@ protected void processDeleteOnExit() { } /** Check if a path exists. + * + * It is highly discouraged to call this method back to back with other + * {@link #getFileStatus(Path)} calls, as this will involve multiple redundant + * RPC calls in HDFS. + * * @param f source path * @return true if the path exists * @throws IOException IO failure @@ -1639,9 +1644,12 @@ public boolean exists(Path f) throws IOException { /** True iff the named path is a directory. * Note: Avoid using this method. Instead reuse the FileStatus * returned by getFileStatus() or listStatus() methods. + * * @param f path to check * @throws IOException IO failure + * @deprecated Use {@link #getFileStatus(Path)} instead */ + @Deprecated public boolean isDirectory(Path f) throws IOException { try { return getFileStatus(f).isDirectory(); @@ -1653,9 +1661,12 @@ public boolean isDirectory(Path f) throws IOException { /** True iff the named path is a regular file. * Note: Avoid using this method. Instead reuse the FileStatus * returned by {@link #getFileStatus(Path)} or listStatus() methods. + * * @param f path to check * @throws IOException IO failure + * @deprecated Use {@link #getFileStatus(Path)} instead */ + @Deprecated public boolean isFile(Path f) throws IOException { try { return getFileStatus(f).isFile(); diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ftp/FTPFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ftp/FTPFileSystem.java index 25fec31ca0..6ce39c16a9 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ftp/FTPFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/ftp/FTPFileSystem.java @@ -644,6 +644,7 @@ private boolean isParentOf(Path parent, Path child) { * @return * @throws IOException */ + @SuppressWarnings("deprecation") private boolean rename(FTPClient client, Path src, Path dst) throws IOException { Path workDir = new Path(client.printWorkingDirectory()); diff --git a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java index 8b1a6d082e..bc4791834b 100644 --- a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java +++ b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java @@ -2142,6 +2142,7 @@ public boolean exists(Path f) throws IOException { * {@inheritDoc} */ @Override + @SuppressWarnings("deprecation") public boolean isDirectory(Path f) throws IOException { incrementStatistic(INVOCATION_IS_DIRECTORY); return super.isDirectory(f); @@ -2152,6 +2153,7 @@ public boolean isDirectory(Path f) throws IOException { * {@inheritDoc} */ @Override + @SuppressWarnings("deprecation") public boolean isFile(Path f) throws IOException { incrementStatistic(INVOCATION_IS_FILE); return super.isFile(f); diff --git a/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeFileSystem.java b/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeFileSystem.java index 7f93c38785..9217532333 100644 --- a/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeFileSystem.java +++ b/hadoop-tools/hadoop-openstack/src/main/java/org/apache/hadoop/fs/swift/snative/SwiftNativeFileSystem.java @@ -201,6 +201,7 @@ public long getBlockSize(Path path) throws IOException { } @Override + @SuppressWarnings("deprecation") public boolean isFile(Path f) throws IOException { try { FileStatus fileStatus = getFileStatus(f); @@ -210,6 +211,7 @@ public boolean isFile(Path f) throws IOException { } } + @SuppressWarnings("deprecation") @Override public boolean isDirectory(Path f) throws IOException {