Github user olegz commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/980#discussion_r78185433
  
    --- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java
 ---
    @@ -245,58 +490,82 @@ private void recoverState(final ProcessContext 
context, final Map<String, String
                             + "this indicates that the file has rotated. Will 
begin tailing current file from beginning.", new 
Object[]{existingTailFile.length(), position});
                 }
     
    -            state = new TailFileState(currentFilename, tailFile, reader, 
position, timestamp, checksum, ByteBuffer.allocate(65536));
    +            states.get(filePath).setState(new TailFileState(filePath, 
tailFile, reader, position, timestamp, length, checksum, 
ByteBuffer.allocate(65536)));
             } else {
    -            resetState(currentFilename);
    +            resetState(filePath);
             }
     
    -        getLogger().debug("Recovered state {}", new Object[]{state});
    +        getLogger().debug("Recovered state {}", new 
Object[]{states.get(filePath).getState()});
         }
     
    -    private void resetState(final String currentFilename) {
    -        expectedRecoveryChecksum = null;
    -        state = new TailFileState(currentFilename, null, null, 0L, 0L, 
null, ByteBuffer.allocate(65536));
    +    private void resetState(final String filePath) {
    +        states.get(filePath).setExpectedRecoveryChecksum(null);
    +        states.get(filePath).setState(new TailFileState(filePath, null, 
null, 0L, 0L, 0L, null, ByteBuffer.allocate(65536)));
         }
     
         @OnStopped
         public void cleanup() {
    -        final TailFileState state = this.state;
    -        if (state == null) {
    +        for (TailFileObject tfo : states.values()) {
    +            cleanReader(tfo);
    +            final TailFileState state = tfo.getState();
    +            tfo.setState(new TailFileState(state.getFilename(), 
state.getFile(), null, state.getPosition(), state.getTimestamp(), 
state.getLength(), state.getChecksum(), state.getBuffer()));
    +        }
    +    }
    +
    +    private void cleanReader(TailFileObject tfo) {
    +        if (tfo.getState() == null) {
                 return;
             }
     
    -        final FileChannel reader = state.getReader();
    +        final FileChannel reader = tfo.getState().getReader();
             if (reader == null) {
                 return;
             }
     
             try {
                 reader.close();
    +            getLogger().debug("Closed FileChannel {}", new 
Object[]{reader});
             } catch (final IOException ioe) {
                 getLogger().warn("Failed to close file handle during cleanup");
             }
    -
    -        getLogger().debug("Closed FileChannel {}", new Object[]{reader});
    -
    -        this.state = new TailFileState(state.getFilename(), 
state.getFile(), null, state.getPosition(), state.getTimestamp(), 
state.getChecksum(), state.getBuffer());
         }
     
         @Override
         public void onTrigger(final ProcessContext context, final 
ProcessSession session) throws ProcessException {
    +        if(isMultiChanging.get()) {
    +            long timeSinceLastLookup = new Date().getTime() - 
lastLookup.get();
    +            if(timeSinceLastLookup > 
context.getProperty(LOOKUP_FREQUENCY).asTimePeriod(TimeUnit.MILLISECONDS)) {
    +                try {
    +                    recoverState(context);
    +                } catch (IOException e) {
    +                    getLogger().warn("Exception raised while looking up 
for new files", e);
    --- End diff --
    
    Did you mean ```getLogger().error(..)```?



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to