HADOOP-13406 S3AFileSystem: Consider reusing filestatus in delete() and mkdirs(). Contributed by Rajesh Balamohan

This commit is contained in:
Steve Loughran 2016-07-25 14:40:55 +01:00
parent 7052ca8804
commit be9e46b42d
1 changed files with 15 additions and 17 deletions

View File

@ -739,7 +739,7 @@ private boolean innerRename(Path src, Path dst) throws IOException,
} else { } else {
copyFile(srcKey, dstKey, srcStatus.getLen()); copyFile(srcKey, dstKey, srcStatus.getLen());
} }
delete(src, false); innerDelete(srcStatus, false);
} else { } else {
LOG.debug("rename: renaming directory {} to {}", src, dst); LOG.debug("rename: renaming directory {} to {}", src, dst);
@ -1065,16 +1065,20 @@ private void removeKeys(List<DeleteObjectsRequest.KeyVersion> keysToDelete,
*/ */
public boolean delete(Path f, boolean recursive) throws IOException { public boolean delete(Path f, boolean recursive) throws IOException {
try { 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) { } catch (AmazonClientException e) {
throw translateException("delete", f, 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 * @param recursive if path is a directory and set to
* true, the directory is deleted else throws an exception. In * true, the directory is deleted else throws an exception. In
* case of a file the recursive can be set to either true or false. * case of a file the recursive can be set to either true or false.
@ -1082,17 +1086,10 @@ public boolean delete(Path f, boolean recursive) throws IOException {
* @throws IOException due to inability to delete a directory or file. * @throws IOException due to inability to delete a directory or file.
* @throws AmazonClientException on failures inside the AWS SDK * @throws AmazonClientException on failures inside the AWS SDK
*/ */
private boolean innerDelete(Path f, boolean recursive) throws IOException, private boolean innerDelete(S3AFileStatus status, boolean recursive)
AmazonClientException { throws IOException, AmazonClientException {
Path f = status.getPath();
LOG.debug("Delete path {} - recursive {}", f , recursive); 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); String key = pathToKey(f);
@ -1318,8 +1315,9 @@ private boolean innerMkdirs(Path f, FsPermission permission)
throws IOException, FileAlreadyExistsException, AmazonClientException { throws IOException, FileAlreadyExistsException, AmazonClientException {
LOG.debug("Making directory: {}", f); LOG.debug("Making directory: {}", f);
incrementStatistic(INVOCATION_MKDIRS); incrementStatistic(INVOCATION_MKDIRS);
FileStatus fileStatus;
try { try {
FileStatus fileStatus = getFileStatus(f); fileStatus = getFileStatus(f);
if (fileStatus.isDirectory()) { if (fileStatus.isDirectory()) {
return true; return true;
@ -1327,10 +1325,10 @@ private boolean innerMkdirs(Path f, FsPermission permission)
throw new FileAlreadyExistsException("Path is a file: " + f); throw new FileAlreadyExistsException("Path is a file: " + f);
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Path fPart = f; Path fPart = f.getParent();
do { do {
try { try {
FileStatus fileStatus = getFileStatus(fPart); fileStatus = getFileStatus(fPart);
if (fileStatus.isDirectory()) { if (fileStatus.isDirectory()) {
break; break;
} }