You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ma...@apache.org on 2020/12/18 19:21:30 UTC

[nifi] branch main updated: NIFI-8102 TailFile can skip characters if tailing a file on NFS mount

This is an automated email from the ASF dual-hosted git repository.

markap14 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new 31c5dc5  NIFI-8102 TailFile can skip characters if tailing a file on NFS mount
31c5dc5 is described below

commit 31c5dc5ab41ebf909b7512154e7519d22936bf89
Author: Denes Arvay <de...@apache.org>
AuthorDate: Fri Dec 18 16:26:58 2020 +0100

    NIFI-8102 TailFile can skip characters if tailing a file on NFS mount
    
    - Force the TailFile processor to recreate and reposition the reader
      by setting it to null in case of a NulCharacterEncounteredException
    - Updated the TestTailFile.testNULContent() to not initialize the
      processor when calling the second run()
    
    Update the reader's position instead of abandoning it.
    
    This closes #4736.
    
    Signed-off-by: Mark Payne <ma...@hotmail.com>
---
 .../java/org/apache/nifi/processors/standard/TailFile.java | 14 +++++++++++++-
 .../org/apache/nifi/processors/standard/TestTailFile.java  |  4 ++--
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java
index 8d96e44..ae7946f 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java
@@ -799,7 +799,19 @@ public class TailFile extends AbstractProcessor {
 
         if (abort.get() != null) {
             session.remove(flowFile);
-            tfo.setState(new TailFileState(tailFile, file, reader, position, timestamp, length, checksum, state.getBuffer()));
+            final long newPosition = positionHolder.get();
+            try {
+                reader.position(newPosition);
+            } catch (IOException ex) {
+                getLogger().warn("Couldn't reposition the reader for {} due to {}", new Object[]{ file, ex }, ex);
+                try {
+                    reader.close();
+                } catch (IOException ex2) {
+                    getLogger().warn("Failed to close reader for {} due to {}", new Object[]{ file, ex2 }, ex2);
+                }
+                reader = null;
+            }
+            tfo.setState(new TailFileState(tailFile, file, reader, newPosition, timestamp, length, checksum, state.getBuffer()));
             throw abort.get();
         }
 
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTailFile.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTailFile.java
index 04bb4a4..808d0ad 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTailFile.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTailFile.java
@@ -190,12 +190,12 @@ public class TestTailFile {
         raf.write(content1.getBytes());
 
         // WHEN
-        runner.run();
+        runner.run(1, false, true);
         if (reposition != null) {
             raf.seek(reposition);
         }
         raf.write(content2.getBytes());
-        runner.run();
+        runner.run(1, true, false);
 
         // THEN
         runner.assertAllFlowFilesTransferred(TailFile.REL_SUCCESS, expected.size());