NIFI-15938 Improve TailFile startup and state recovery#11245
NIFI-15938 Improve TailFile startup and state recovery#11245ing-mattioni wants to merge 1 commit into
Conversation
exceptionfactory
left a comment
There was a problem hiding this comment.
Thanks for proposing these improvements @ing-mattioni.
On initial review, I raised some concerns about the introduction of several try-catch blocks. These seem unnecessary without further explanation.
Some of the other changes also raise implementation questions, so overall, some clarification and refinement is needed before this can go forward.
|
|
||
| private void initStates(final List<String> filesToTail, final Map<String, String> statesMap, final boolean isCleared) { | ||
| int fileIndex = 0; | ||
| final Set<String> filesToTailSet = new HashSet<>(filesToTail); |
There was a problem hiding this comment.
| final Set<String> filesToTailSet = new HashSet<>(filesToTail); | |
| final Set<String> uniqueFilesToTail = new HashSet<>(filesToTail); |
There was a problem hiding this comment.
Applied. I renamed filesToTailSet to uniqueFilesToTail for clarity.
| } catch (final RuntimeException e) { | ||
| getLogger().warn("Ignoring malformed TailFile state key {}", key, e); | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Is there a particular reason for introducing this try-catch? The Processor should control the state content, avoiding potential incorrect formatting.
There was a problem hiding this comment.
Agreed. I removed this try/catch. TailFile controls the persisted state key format, so adding defensive handling for malformed internal state is not needed here.
| states.put(value, new TailFileObject(index, statesMap, preAllocatedBufferSize)); | ||
| } catch (final RuntimeException e) { | ||
| getLogger().warn("Ignoring malformed TailFile state for {}", value, e); | ||
| } |
There was a problem hiding this comment.
This catch also seems too broad and not necessary.
There was a problem hiding this comment.
Agreed. I removed this broad catch as well. If the processor-controlled state cannot be restored, that should not be silently ignored by skipping the file.
|
|
||
| private void initStates(final List<String> filesToTail, final Map<String, String> statesMap, final boolean isCleared) { | ||
| int fileIndex = 0; | ||
| final Set<String> filesToTailSet = new HashSet<>(filesToTail); |
There was a problem hiding this comment.
What is the reason for creating this wrapping Set?
There was a problem hiding this comment.
The Set is used to avoid repeated linear List.contains() checks while reconciling restored state and removing files that are no longer tailed. With many matching files, keeping this as a List would make startup/state reconciliation trend toward O(n²). The original filesToTail list is still used when adding new states, so ordering is preserved.
f1b75c0 to
a19f427
Compare
|
Thank you @exceptionfactory ; I've updated the PR based on the review. The added try/catch blocks have been removed, and the Set variable has been renamed to "uniqueFilesToTail". I kept the Set conversion because it avoids repeated linear membership checks during state reconciliation, which is important when TailFile starts with many matching files. |
Summary
NIFI-15938
This pull request updates
TailFileto improve multi-file startup behavior and make persisted state recovery more robust.The changes focus on startup performance, rollover state restoration, malformed persisted state handling, read-loop buffer behavior, and buffer-size validation.
Changes
HashSetmembershiptailingPostRolloverstate correctlyKey fixes, more technical description:
Tracking
Please complete the following tracking steps prior to pull request creation.
Issue Tracking
Pull Request Tracking
NIFI-00000NIFI-00000VerifiedstatusPull Request Formatting
mainbranchVerification
Please indicate the verification steps performed prior to pull request creation.
Build
./mvnw clean install -P contrib-checkModule-level verification performed:
.\mvnw.cmd --% -pl :nifi-standard-processors -am -Dtest=TestTailFile,TestTailFileSimpleScenarios,TestTailFileGeneratedScenarios -Dsurefire.failIfNoSpecifiedTests=false testAdditional verification performed:
.\mvnw.cmd --% -pl :nifi-standard-processors -Pcontrib-check validateLicensing
LICENSEandNOTICEfilesNo new dependencies were added.
Documentation
No user-facing documentation files were changed.