NIFI-15319 Decrease memory counter after buffer shutdown in ConsumeKinesis#10633
Closed
awelless wants to merge 1 commit intoapache:mainfrom
Closed
NIFI-15319 Decrease memory counter after buffer shutdown in ConsumeKinesis#10633awelless wants to merge 1 commit intoapache:mainfrom
awelless wants to merge 1 commit intoapache:mainfrom
Conversation
awelless
commented
Dec 11, 2025
| } else { | ||
| logger.debug("Shutting down the buffer {}. Checkpointing last consumed record", bufferId); | ||
| final Collection<RecordBatch> invalidatedBatches = buffer.shutdownBuffer(checkpointer); | ||
| memoryTracker.freeMemory(invalidatedBatches, bufferId); |
Contributor
Author
There was a problem hiding this comment.
This absent line was causing the memory tracker to think the buffer is full, even when no data was there.
| logger.debug("Reserved {} bytes for {} records. Total consumed memory: {} bytes", | ||
| consumedBytes, recordBatch.size(), newConsumedBytes); | ||
| logger.debug("Reserved {} bytes for {} records for buffer {}. Total consumed memory: {} bytes", | ||
| consumedBytes, recordBatch.size(), bufferId, newConsumedBytes); |
Contributor
Author
There was a problem hiding this comment.
Logging bufferId in reserveMemory and freeMemory allows us to precisely track memory operations for each buffer in the logs.
| private Collection<RecordBatch> drainInvalidatedBatches() { | ||
| if (!invalidated.get()) { | ||
| throw new IllegalStateException("Can't drain invalidated batches for valid shard buffer: " + bufferId); | ||
| } |
Contributor
Author
There was a problem hiding this comment.
Just a safety check to make sure we perform this destructive action for invalidated buffers only.
| } catch (final ShutdownException e) { | ||
| logger.warn("Failed to checkpoint records due to shutdown. Ignoring checkpoint", e); | ||
| return; | ||
| } catch (final RuntimeException e) { |
Contributor
Author
There was a problem hiding this comment.
It's essential to ensure no exception is thrown from the buffer methods, so that freeMemory is always called.
exceptionfactory
approved these changes
Dec 11, 2025
Contributor
exceptionfactory
left a comment
There was a problem hiding this comment.
Thanks for addressing this issue and additional logs, the changes look good. +1 merging
mark-bathori
pushed a commit
to mark-bathori/nifi
that referenced
this pull request
Feb 5, 2026
…nesis This closes apache#10633 Signed-off-by: David Handermann <exceptionfactory@apache.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
NIFI-15319
Memory counter is decreased when
shutdownShardConsumptionis called. As tested, this method is called not only during application shutdown, but also as a part of graceful lease handoff for a single shard.Added more information in the debug logs.
Tracking
Please complete the following tracking steps prior to pull request creation.
Issue Tracking
Pull Request Tracking
NIFI-00000NIFI-00000Pull Request Formatting
mainbranchVerification
Please indicate the verification steps performed prior to pull request creation.
Build
./mvnw clean install -P contrib-checkLicensing
LICENSEandNOTICEfilesDocumentation