You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2021/01/31 20:35:45 UTC

[GitHub] [nifi] adenes opened a new pull request #4792: NIFI-8183 TailFile intermittently creates records with ascii NULL after rollover

adenes opened a new pull request #4792:
URL: https://github.com/apache/nifi/pull/4792


   TailFile processor configured to an NFS mount reads unexpected NUL characters after a file had been rolled over.
   Fixed by adding the NUL check to the part where the rolled over file is being read.
   
   
   ### For all changes:
   - [x] Is there a JIRA ticket associated with this PR? Is it referenced 
        in the commit message?
   
   - [x] 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.
   
   - [x] Has your PR been rebased against the latest commit within the target branch (typically `main`)?
   
   - [x] 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:
   - [x] Have you ensured that the full suite of tests is executed via `mvn -Pcontrib-check clean install` at the root `nifi` folder?
   - [x] Have you written or updated unit tests to verify your changes?
   - [x] Have you verified that the full build is successful on JDK 8?
   - [x] 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](http://www.apache.org/legal/resolved.html#category-a)? 
   - [ ] 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.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] tpalfy commented on a change in pull request #4792: NIFI-8183 TailFile intermittently creates records with ascii NULL after rollover

Posted by GitBox <gi...@apache.org>.
tpalfy commented on a change in pull request #4792:
URL: https://github.com/apache/nifi/pull/4792#discussion_r567717333



##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java
##########
@@ -1172,19 +1188,28 @@ private boolean recoverRolledFiles(final ProcessContext context, final ProcessSe
                 final File firstFile = rolledOffFiles.get(0);
 
                 final long startNanos = System.nanoTime();
+                final Boolean reReadOnNul = context.getProperty(REREAD_ON_NUL).asBoolean();
                 if (position > 0) {
-                    try (final InputStream fis = new FileInputStream(firstFile);
-                            final CheckedInputStream in = new CheckedInputStream(fis, new CRC32())) {
-                        StreamUtils.copy(in, new NullOutputStream(), position);
+                    try (final FileInputStream fis = new FileInputStream(firstFile)) {

Review comment:
       I think we don't need `readLines` here because we already processed to content up to this point.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] Lehel44 commented on a change in pull request #4792: NIFI-8183 TailFile intermittently creates records with ascii NULL after rollover

Posted by GitBox <gi...@apache.org>.
Lehel44 commented on a change in pull request #4792:
URL: https://github.com/apache/nifi/pull/4792#discussion_r568482301



##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java
##########
@@ -1184,7 +1191,15 @@ private boolean recoverRolledFiles(final ProcessContext context, final ProcessSe
                             // This is the same file that we were reading when we shutdown. Start reading from this point on.
                             rolledOffFiles.remove(0);
                             FlowFile flowFile = session.create();
-                            flowFile = session.importFrom(in, flowFile);
+                            try {

Review comment:
       Would you extract this nested try block to a separate method?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] adenes commented on a change in pull request #4792: NIFI-8183 TailFile intermittently creates records with ascii NULL after rollover

Posted by GitBox <gi...@apache.org>.
adenes commented on a change in pull request #4792:
URL: https://github.com/apache/nifi/pull/4792#discussion_r569276813



##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java
##########
@@ -1184,7 +1191,15 @@ private boolean recoverRolledFiles(final ProcessContext context, final ProcessSe
                             // This is the same file that we were reading when we shutdown. Start reading from this point on.
                             rolledOffFiles.remove(0);
                             FlowFile flowFile = session.create();
-                            flowFile = session.importFrom(in, flowFile);
+                            try {

Review comment:
       Thanks @Lehel44 for the suggestion.
   Although I agree that the method gets more and more complicated but I tried to extract these lines to a separate method and unless I do a bigger refactor it doesn't really simplify things.
   My biggest concern with it that the new method needs 5 parameters (`ProcessContext context, ProcessSession session, List<File> rolledOffFiles, File file, FileInputStream fis`) and there's no good way to check whether the `FileInputStream` belongs to the given `File`.
   
   It'd be definitely worth to do a bigger refactor on this method, but I'd suggest doing it in a separate PR.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] markap14 closed pull request #4792: NIFI-8183 TailFile intermittently creates records with ascii NULL after rollover

Posted by GitBox <gi...@apache.org>.
markap14 closed pull request #4792:
URL: https://github.com/apache/nifi/pull/4792


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] markap14 commented on a change in pull request #4792: NIFI-8183 TailFile intermittently creates records with ascii NULL after rollover

Posted by GitBox <gi...@apache.org>.
markap14 commented on a change in pull request #4792:
URL: https://github.com/apache/nifi/pull/4792#discussion_r569490344



##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java
##########
@@ -1184,7 +1191,15 @@ private boolean recoverRolledFiles(final ProcessContext context, final ProcessSe
                             // This is the same file that we were reading when we shutdown. Start reading from this point on.
                             rolledOffFiles.remove(0);
                             FlowFile flowFile = session.create();
-                            flowFile = session.importFrom(in, flowFile);
+                            try {
+                                ByteArrayOutputStream out = new ByteArrayOutputStream();

Review comment:
       This approach is going to buffer everything that gets read into the ByteArrayOutputStream. This could potentially be a huge amount of data. We want to be sure that we don't buffer that up. Instead, I would recommend an approach like:
   ```
   try (final OutputStream out = session.write(flowFile)) {
     readLines(fis.getChannel(), ByteBuffer.allocate(65536), out, new CRC32(), reReadOnNul, true);
   }
   ```
   This allows us to write directly to the content repository instead of buffering the data in a ByteArrayOutputStream.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] adenes commented on a change in pull request #4792: NIFI-8183 TailFile intermittently creates records with ascii NULL after rollover

Posted by GitBox <gi...@apache.org>.
adenes commented on a change in pull request #4792:
URL: https://github.com/apache/nifi/pull/4792#discussion_r569493455



##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java
##########
@@ -1184,7 +1191,15 @@ private boolean recoverRolledFiles(final ProcessContext context, final ProcessSe
                             // This is the same file that we were reading when we shutdown. Start reading from this point on.
                             rolledOffFiles.remove(0);
                             FlowFile flowFile = session.create();
-                            flowFile = session.importFrom(in, flowFile);
+                            try {
+                                ByteArrayOutputStream out = new ByteArrayOutputStream();

Review comment:
       oh, wow, I wasn't aware of this version of `session.write`. I was also a bit concerned about the buffering, thanks, will update the PR




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] Lehel44 commented on a change in pull request #4792: NIFI-8183 TailFile intermittently creates records with ascii NULL after rollover

Posted by GitBox <gi...@apache.org>.
Lehel44 commented on a change in pull request #4792:
URL: https://github.com/apache/nifi/pull/4792#discussion_r568482301



##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java
##########
@@ -1184,7 +1191,15 @@ private boolean recoverRolledFiles(final ProcessContext context, final ProcessSe
                             // This is the same file that we were reading when we shutdown. Start reading from this point on.
                             rolledOffFiles.remove(0);
                             FlowFile flowFile = session.create();
-                            flowFile = session.importFrom(in, flowFile);
+                            try {

Review comment:
       Would you extract this nested try block to a separate method?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] markap14 commented on pull request #4792: NIFI-8183 TailFile intermittently creates records with ascii NULL after rollover

Posted by GitBox <gi...@apache.org>.
markap14 commented on pull request #4792:
URL: https://github.com/apache/nifi/pull/4792#issuecomment-772710526


   Thanks for the update @adenes LGTM +1 will merge to `main`.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] adenes commented on a change in pull request #4792: NIFI-8183 TailFile intermittently creates records with ascii NULL after rollover

Posted by GitBox <gi...@apache.org>.
adenes commented on a change in pull request #4792:
URL: https://github.com/apache/nifi/pull/4792#discussion_r569524878



##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java
##########
@@ -1184,7 +1191,15 @@ private boolean recoverRolledFiles(final ProcessContext context, final ProcessSe
                             // This is the same file that we were reading when we shutdown. Start reading from this point on.
                             rolledOffFiles.remove(0);
                             FlowFile flowFile = session.create();
-                            flowFile = session.importFrom(in, flowFile);
+                            try {
+                                ByteArrayOutputStream out = new ByteArrayOutputStream();

Review comment:
       Pushed a new commit: I got rid of the BAOS, but used `session.write(FlowFile, OutputStreamCallback)` because we need the updated FF later.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] adenes commented on a change in pull request #4792: NIFI-8183 TailFile intermittently creates records with ascii NULL after rollover

Posted by GitBox <gi...@apache.org>.
adenes commented on a change in pull request #4792:
URL: https://github.com/apache/nifi/pull/4792#discussion_r567762986



##########
File path: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java
##########
@@ -1172,19 +1188,28 @@ private boolean recoverRolledFiles(final ProcessContext context, final ProcessSe
                 final File firstFile = rolledOffFiles.get(0);
 
                 final long startNanos = System.nanoTime();
+                final Boolean reReadOnNul = context.getProperty(REREAD_ON_NUL).asBoolean();
                 if (position > 0) {
-                    try (final InputStream fis = new FileInputStream(firstFile);
-                            final CheckedInputStream in = new CheckedInputStream(fis, new CRC32())) {
-                        StreamUtils.copy(in, new NullOutputStream(), position);
+                    try (final FileInputStream fis = new FileInputStream(firstFile)) {

Review comment:
       Thanks @tpalfy , I have updated the change according to your comment. I also extracted a couple of repeating lines from the `readLines()` method.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org