-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow rename() to overwrite, fix an uncaught ex and reenable UT #18263
Allow rename() to overwrite, fix an uncaught ex and reenable UT #18263
Conversation
2fec0ec
to
b597c61
Compare
dora/core/client/fs/src/main/java/alluxio/client/file/DoraCacheFileSystem.java
Show resolved
Hide resolved
@@ -463,6 +463,7 @@ message RenamePOptions { | |||
optional FileSystemMasterCommonPOptions commonOptions = 1; | |||
optional bool persist = 2; | |||
optional S3SyntaxOptions s3SyntaxOptions = 3; | |||
optional bool overwrite = 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add overwrite flag and corresponding check to rename method.
Also, not sure what to do about |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since I don't have the context, leave a comment, thanks!
dora/core/client/fs/src/main/java/alluxio/client/file/DoraCacheFileSystem.java
Outdated
Show resolved
Hide resolved
if (ex instanceof StatusRuntimeException) { | ||
Status.Code code = ((StatusRuntimeException) ex).getStatus().getCode(); | ||
if (code == Status.FAILED_PRECONDITION.getCode()) { | ||
// throw new RuntimeException(ex.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not throw here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just not sure this is the appropriate exception to throw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jackson-Wang-7 WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the FAILED_PRECONDITION, I think it may be not allowed to rename the file to file but it's ok to rename the file into a directory. so we may need a log here and wait for the result of 2nd try?
if (src == dst) { | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (src == dst) { | |
return true; | |
} | |
if (src.equals(dst)) { | |
LOG.debug("Renaming {} to the same location", src); | |
return true; | |
} |
* @param dstPath srcPath | ||
* @return true in success, false if fail | ||
*/ | ||
public boolean renameInternal(Path src, Path dst, AlluxioURI srcPath, AlluxioURI dstPath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i tried to rename this one
private boolean tryMoveIntoDirectory(AlluxioURI srcPath, AlluxioURI dstPath)
throws IOException, AlluxioException {
ensureExists(srcPath);
URIStatus dstStatus;
dstStatus = mFileSystem.getStatus(dstPath);
// If the destination is an existing folder, try to move the src into the folder
if (dstStatus != null && dstStatus.isFolder()) {
dstPath = dstPath.joinUnsafe(srcPath.getName());
} else {
return false;
}
mFileSystem.rename(srcPath, dstPath);
return true;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, looks great
throw toHdfsIOException(e); | ||
LOG.warn("rename failed: {}", toHdfsIOException(e)); | ||
return renameInternal(src, dst, srcPath, dstPath); | ||
} catch (AlluxioException e) { | ||
return renameInternal(src, dst, srcPath, dstPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i had to write try-catch inside this catch but i figure it's ok
} catch (AlluxioRuntimeException | AlluxioException e) {
Exception exToLog = e;
if (e instanceof AlluxioRuntimeException) {
exToLog = toHdfsIOException((AlluxioRuntimeException) e);
}
try {
boolean res = tryMoveIntoDirectory(srcPath, dstPath);
if (!res) {
LOG.warn("Failed to rename file and dst {} is not a directory", dst, exToLog);
}
return res;
} catch (IOException | AlluxioException | AlluxioRuntimeException e2) {
LOG.error("Failed to rename file {} and failed to move into dst directory {}",
src, dst, exToLog);
return false;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we package the try-catch into the tryMoveIntoDirectory
? then we can reduce the nested try-catch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i just wanted to have the ex from the 1st try AlluxioRuntimeException | AlluxioException e
and the ex from the tryMoveIntoDirectory
together. So I can decide which one to log, and maybe log both?
dora/core/client/hdfs/src/main/java/alluxio/hadoop/AbstractFileSystem.java
Show resolved
Hide resolved
throw toHdfsIOException(e); | ||
LOG.warn("rename failed: {}", toHdfsIOException(e)); | ||
return renameInternal(src, dst, srcPath, dstPath); | ||
} catch (AlluxioException e) { | ||
return renameInternal(src, dst, srcPath, dstPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we package the try-catch into the tryMoveIntoDirectory
? then we can reduce the nested try-catch.
dora/core/client/hdfs/src/main/java/alluxio/hadoop/AbstractFileSystem.java
Show resolved
Hide resolved
dora/core/client/hdfs/src/main/java/alluxio/hadoop/AbstractFileSystem.java
Outdated
Show resolved
Hide resolved
dora/core/client/hdfs/src/main/java/alluxio/hadoop/AbstractFileSystem.java
Outdated
Show resolved
Hide resolved
dora/core/client/hdfs/src/main/java/alluxio/hadoop/AbstractFileSystem.java
Outdated
Show resolved
Hide resolved
dora/core/client/hdfs/src/main/java/alluxio/hadoop/AbstractFileSystem.java
Show resolved
Hide resolved
if (ex instanceof StatusRuntimeException) { | ||
Status.Code code = ((StatusRuntimeException) ex).getStatus().getCode(); | ||
if (code == Status.FAILED_PRECONDITION.getCode()) { | ||
// throw new RuntimeException(ex.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jackson-Wang-7 WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
dora/core/client/fs/src/main/java/alluxio/client/file/DoraCacheFileSystem.java
Outdated
Show resolved
Hide resolved
dora/core/client/fs/src/main/java/alluxio/client/file/DoraCacheFileSystem.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Automated checks report:
Some checks failed. Please fix the reported issues and reply 'alluxio-bot, check this please' to re-run checks. |
Automated checks report:
All checks passed! |
alluxio-bot, merge this please |
### What changes are proposed in this pull request? As the title states, this PR does a few things: 1. Allow rename() to overwrite an existing path, if specified in the option 2. The method `rename` in `AbstractFileSystem`, now will process the input path and rerun `rename` method when caught `AlluxioException` or `AlluxioRuntimeException`. Instead of log the exception and return end. 3. Also add some path checks during the rename 4. Reenable `FileSystemRenameIntegrationTest` by adding configs to `LocalAlluxioClusterResource` and reenable UT cases. pr-link: Alluxio#18263 change-id: cid-2870bf87fea8a3b2419e5b10a05423ff2dede6a2
What changes are proposed in this pull request?
As the title states, this PR does a few things:
rename
inAbstractFileSystem
, now will process the input path and rerunrename
method when caughtAlluxioException
orAlluxioRuntimeException
. Instead of log the exception and return end.FileSystemRenameIntegrationTest
by adding configs toLocalAlluxioClusterResource
and reenable UT cases.