Skip to content
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

Merged
merged 25 commits into from
Nov 10, 2023

Conversation

voddle
Copy link
Contributor

@voddle voddle commented Oct 12, 2023

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.

@@ -463,6 +463,7 @@ message RenamePOptions {
optional FileSystemMasterCommonPOptions commonOptions = 1;
optional bool persist = 2;
optional S3SyntaxOptions s3SyntaxOptions = 3;
optional bool overwrite = 4;
Copy link
Contributor Author

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.

@voddle
Copy link
Contributor Author

voddle commented Oct 27, 2023

Also, not sure what to do about basicRenameTest7, does dora support get file status before the stream is closed?

Copy link
Contributor

@YichuanSun YichuanSun left a 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!

if (ex instanceof StatusRuntimeException) {
Status.Code code = ((StatusRuntimeException) ex).getStatus().getCode();
if (code == Status.FAILED_PRECONDITION.getCode()) {
// throw new RuntimeException(ex.getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not throw here?

Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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?

Comment on lines 702 to 704
if (src == dst) {
return true;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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) {
Copy link
Contributor

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;
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, looks great

Comment on lines 713 to 718
throw toHdfsIOException(e);
LOG.warn("rename failed: {}", toHdfsIOException(e));
return renameInternal(src, dst, srcPath, dstPath);
} catch (AlluxioException e) {
return renameInternal(src, dst, srcPath, dstPath);
Copy link
Contributor

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;
      }

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree

Copy link
Contributor

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?

Comment on lines 713 to 718
throw toHdfsIOException(e);
LOG.warn("rename failed: {}", toHdfsIOException(e));
return renameInternal(src, dst, srcPath, dstPath);
} catch (AlluxioException e) {
return renameInternal(src, dst, srcPath, dstPath);
Copy link
Contributor

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.

if (ex instanceof StatusRuntimeException) {
Status.Code code = ((StatusRuntimeException) ex).getStatus().getCode();
if (code == Status.FAILED_PRECONDITION.getCode()) {
// throw new RuntimeException(ex.getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@Jackson-Wang-7 Jackson-Wang-7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@YichuanSun YichuanSun added the type-bug This issue is about a bug label Nov 9, 2023
Copy link
Contributor

@jiacheliu3 jiacheliu3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@jiacheliu3 jiacheliu3 changed the title Fix a exception leaking in AbstractFileSystem.rename() Allow rename() to overwrite, fix an uncaught ex and reenable UT on rename Nov 9, 2023
@alluxio-bot
Copy link
Contributor

Automated checks report:

  • PR title follows the conventions: FAIL
    • The title of the PR does not pass all the checks. Please fix the following issues:
      • Title is too long (73 characters). Must be at most 72 characters.
  • Commits associated with Github account: PASS

Some checks failed. Please fix the reported issues and reply 'alluxio-bot, check this please' to re-run checks.

@jiacheliu3 jiacheliu3 changed the title Allow rename() to overwrite, fix an uncaught ex and reenable UT on rename Allow rename() to overwrite, fix an uncaught ex and reenable UT Nov 9, 2023
@alluxio-bot
Copy link
Contributor

Automated checks report:

  • PR title follows the conventions: PASS
  • Commits associated with Github account: PASS

All checks passed!

@jiacheliu3
Copy link
Contributor

alluxio-bot, merge this please

@alluxio-bot alluxio-bot merged commit 328ee8c into Alluxio:main Nov 10, 2023
14 checks passed
ssz1997 pushed a commit to ssz1997/alluxio that referenced this pull request Dec 15, 2023
### 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug This issue is about a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants