Skip to content

Commit

Permalink
HADOOP-13406 S3AFileSystem: Consider reusing filestatus in delete() a…
Browse files Browse the repository at this point in the history
…nd mkdirs(). Contributed by Rajesh Balamohan
  • Loading branch information
steveloughran committed Jul 25, 2016
1 parent 7052ca8 commit be9e46b
Showing 1 changed file with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ private boolean innerRename(Path src, Path dst) throws IOException,
} else {
copyFile(srcKey, dstKey, srcStatus.getLen());
}
delete(src, false);
innerDelete(srcStatus, false);
} else {
LOG.debug("rename: renaming directory {} to {}", src, dst);

Expand Down Expand Up @@ -1065,34 +1065,31 @@ private void removeKeys(List<DeleteObjectsRequest.KeyVersion> keysToDelete,
*/
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.
* @return true if delete is successful else false.
* @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);

Expand Down Expand Up @@ -1318,19 +1315,20 @@ private boolean innerMkdirs(Path f, FsPermission permission)
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;
} else {
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;
}
Expand Down

0 comments on commit be9e46b

Please sign in to comment.