hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [2/4] hadoop git commit: HADOOP-13406 S3AFileSystem: Consider reusing filestatus in delete() and mkdirs(). Contributed by Rajesh Balamohan
Date Mon, 25 Jul 2016 13:45:29 GMT
HADOOP-13406 S3AFileSystem: Consider reusing filestatus in delete() and mkdirs(). Contributed
by Rajesh Balamohan


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/271e7bb0
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/271e7bb0
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/271e7bb0

Branch: refs/heads/branch-2
Commit: 271e7bb00b1ee69d27417213653dc04e9c487789
Parents: bdde7ed
Author: Steve Loughran <stevel@apache.org>
Authored: Mon Jul 25 14:40:55 2016 +0100
Committer: Steve Loughran <stevel@apache.org>
Committed: Mon Jul 25 14:44:03 2016 +0100

----------------------------------------------------------------------
 .../org/apache/hadoop/fs/s3a/S3AFileSystem.java | 32 +++++++++-----------
 1 file changed, 15 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/271e7bb0/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java
----------------------------------------------------------------------
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 08ac957..5ef1105 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
@@ -749,7 +749,7 @@ public class S3AFileSystem extends FileSystem {
       } else {
         copyFile(srcKey, dstKey, srcStatus.getLen());
       }
-      delete(src, false);
+      innerDelete(srcStatus, false);
     } else {
       LOG.debug("rename: renaming directory {} to {}", src, dst);
 
@@ -1075,16 +1075,20 @@ public class S3AFileSystem extends FileSystem {
    */
   public boolean delete(Path f, boolean recursive) throws IOException {
     try {
-      return innerDelete(f, recursive);
+      return innerDelete(getFileStatus(f), recursive);
+    } catch (FileNotFoundException e) {
+      LOG.debug("Couldn't delete {} - does not exist", f);
+      instrumentation.errorIgnored();
+      return false;
     } catch (AmazonClientException e) {
       throw translateException("delete", f, e);
     }
   }
 
   /**
-   * Delete a path. See {@link #delete(Path, boolean)}.
+   * Delete an object. See {@link #delete(Path, boolean)}.
    *
-   * @param f the path to delete.
+   * @param status fileStatus object
    * @param recursive if path is a directory and set to
    * true, the directory is deleted else throws an exception. In
    * case of a file the recursive can be set to either true or false.
@@ -1092,17 +1096,10 @@ public class S3AFileSystem extends FileSystem {
    * @throws IOException due to inability to delete a directory or file.
    * @throws AmazonClientException on failures inside the AWS SDK
    */
-  private boolean innerDelete(Path f, boolean recursive) throws IOException,
-      AmazonClientException {
+  private boolean innerDelete(S3AFileStatus status, boolean recursive)
+      throws IOException, AmazonClientException {
+    Path f = status.getPath();
     LOG.debug("Delete path {} - recursive {}", f , recursive);
-    S3AFileStatus status;
-    try {
-      status = getFileStatus(f);
-    } catch (FileNotFoundException e) {
-      LOG.debug("Couldn't delete {} - does not exist", f);
-      instrumentation.errorIgnored();
-      return false;
-    }
 
     String key = pathToKey(f);
 
@@ -1328,8 +1325,9 @@ public class S3AFileSystem extends FileSystem {
       throws IOException, FileAlreadyExistsException, AmazonClientException {
     LOG.debug("Making directory: {}", f);
     incrementStatistic(INVOCATION_MKDIRS);
+    FileStatus fileStatus;
     try {
-      FileStatus fileStatus = getFileStatus(f);
+      fileStatus = getFileStatus(f);
 
       if (fileStatus.isDirectory()) {
         return true;
@@ -1337,10 +1335,10 @@ public class S3AFileSystem extends FileSystem {
         throw new FileAlreadyExistsException("Path is a file: " + f);
       }
     } catch (FileNotFoundException e) {
-      Path fPart = f;
+      Path fPart = f.getParent();
       do {
         try {
-          FileStatus fileStatus = getFileStatus(fPart);
+          fileStatus = getFileStatus(fPart);
           if (fileStatus.isDirectory()) {
             break;
           }


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message