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

NIFI-8200: Modifying PutAzureDataLakeStorage to delete temp file if e… #4815

Closed
wants to merge 10 commits into from

Conversation

timeabarna
Copy link
Contributor

@timeabarna timeabarna commented Feb 10, 2021

…xception was thrown in uploadContent()

https://issues.apache.org/jira/browse/NIFI-8200

Description of PR

delete temp file if exception was thrown in uploadContent()

In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:

For all changes:

  • Is there a JIRA ticket associated with this PR? Is it referenced
    in the commit message?

  • Does your PR title start with NIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.

  • Has your PR been rebased against the latest commit within the target branch (typically main)?

  • Is your initial contribution a single, squashed commit? Additional commits in response to PR reviewer feedback should be made on this branch and pushed to allow change tracking. Do not squash or use --force when pushing to allow for clean monitoring of changes.

For code changes:

  • Have you ensured that the full suite of tests is executed via mvn -Pcontrib-check clean install at the root nifi folder?
  • Have you written or updated unit tests to verify your changes?
  • Have you verified that the full build is successful on JDK 8?
  • Have you verified that the full build is successful on JDK 11?
  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE file, including the main LICENSE file under nifi-assembly?
  • If applicable, have you updated the NOTICE file, including the main NOTICE file found under nifi-assembly?
  • If adding new Properties, have you added .displayName in addition to .name (programmatic access) for each of the new properties?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered?

Note:

Please ensure that once the PR is submitted, you check GitHub Actions CI for build issues and submit an update to your PR as soon as possible.

Copy link
Contributor

@pgyori pgyori left a comment

Choose a reason for hiding this comment

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

Thank you for the fix! I tested it with interrupting internet access while uploading a large file. I found one case that I think needs to be handled, please check my comment with a proposed solution.

@@ -126,6 +126,9 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
if (length > 0) {
try (final InputStream rawIn = session.read(flowFile); final BufferedInputStream bufferedIn = new BufferedInputStream(rawIn)) {
uploadContent(fileClient, bufferedIn, length);
} catch (Exception e) {
fileClient.delete();
throw e;
Copy link
Contributor

Choose a reason for hiding this comment

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

Exception e is suppressed if fileClient.delete() also throws an exception. My recommendation is to put a try-catch-finally around delete(). In the catch only an error message needs to be logged, and in the finally the original exception 'e' can be thrown forward.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your help, corrected in the next commit

Copy link
Contributor

@pgyori pgyori left a comment

Choose a reason for hiding this comment

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

Thank you!
LGTM

@jfrazee
Copy link
Member

jfrazee commented Feb 15, 2021

@timeabarna What happens when an existing file is being overwritten with the Conflict Resolution Strategy set to replace?

@timeabarna
Copy link
Contributor Author

@timeabarna What happens when an existing file is being overwritten with the Conflict Resolution Strategy set to replace?

@jfrazee Thanks for pointing this out. I've checked the original version and the behaviour is the following:

  • The original file has been replaced with a 0 byte file
  • uploading content started
  • if uploading failed the original data was gone and the 0 byte file remained

With this current modification the behaviour:

  • file replaced with a 0 byte file
  • uploading content started
  • if failed the 0 byte file was removed (if deletion fails, the 0 byte file remains)

I'm exploring the possibility using temp files instead of inline replacement however I think this should be covered by another Jira ticket.

@jfrazee
Copy link
Member

jfrazee commented Feb 16, 2021

@timeabarna That's what I figured. It's not ideal, but this isn't a regression. Can we clarify the delete behavior in the docs?

@jfrazee
Copy link
Member

jfrazee commented Feb 16, 2021

@timeabarna Oh, also, yes it makes sense to have another JIRA for some more sophisticated handling, which should probably be done. Ideally we should try to have the same behavior we can get with HDFS, which I think is achievable since renames are atomic.

@timeabarna
Copy link
Contributor Author

@timeabarna That's what I figured. It's not ideal, but this isn't a regression. Can we clarify the delete behavior in the docs?

@jfrazee Sure thing, will update the docs accordingly

</ul>

</body>
</html>
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a trailing newline?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All suggestions have been applied. Thanks Joey for your help.

timeabarna and others added 7 commits February 19, 2021 07:48
…ain/resources/docs/org.apache.nifi.processors.azure.storage.PutAzureDataLakeStorage/additionalDetails.html

Co-authored-by: Joey <joey.frazee@icloud.com>
…ain/resources/docs/org.apache.nifi.processors.azure.storage.PutAzureDataLakeStorage/additionalDetails.html

Co-authored-by: Joey <joey.frazee@icloud.com>
…ain/resources/docs/org.apache.nifi.processors.azure.storage.PutAzureDataLakeStorage/additionalDetails.html

Co-authored-by: Joey <joey.frazee@icloud.com>
…ain/resources/docs/org.apache.nifi.processors.azure.storage.PutAzureDataLakeStorage/additionalDetails.html

Co-authored-by: Joey <joey.frazee@icloud.com>
…ain/resources/docs/org.apache.nifi.processors.azure.storage.PutAzureDataLakeStorage/additionalDetails.html

Co-authored-by: Joey <joey.frazee@icloud.com>
…ain/resources/docs/org.apache.nifi.processors.azure.storage.PutAzureDataLakeStorage/additionalDetails.html

Co-authored-by: Joey <joey.frazee@icloud.com>
@jfrazee
Copy link
Member

jfrazee commented Feb 21, 2021

Thanks for this @timeabarna +1

@jfrazee jfrazee closed this in 59ad21f Feb 21, 2021
asfgit pushed a commit that referenced this pull request Feb 25, 2021
…eption was thrown in uploadContent()

This closes #4815

Signed-off-by: Joey Frazee <jfrazee@apache.org>
driesva pushed a commit to driesva/nifi that referenced this pull request Mar 19, 2021
…eption was thrown in uploadContent()

This closes apache#4815

Signed-off-by: Joey Frazee <jfrazee@apache.org>
krisztina-zsihovszki pushed a commit to krisztina-zsihovszki/nifi that referenced this pull request Jun 28, 2022
…eption was thrown in uploadContent()

This closes apache#4815

Signed-off-by: Joey Frazee <jfrazee@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants