Draft
Add partition-level idle detection to prevent message loss on ownership transfer#39
Conversation
Co-authored-by: nodece <16235121+nodece@users.noreply.github.com>
Co-authored-by: nodece <16235121+nodece@users.noreply.github.com>
…t magic numbers Co-authored-by: nodece <16235121+nodece@users.noreply.github.com>
… idle detection Co-authored-by: nodece <16235121+nodece@users.noreply.github.com>
… improve test reliability Co-authored-by: nodece <16235121+nodece@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add partition-level idle detection for consumer to prevent message loss
Add partition-level idle detection to prevent message loss on ownership transfer
Jan 15, 2026
Copilot stopped work on behalf of
nodece due to an error
January 15, 2026 04:09
Owner
|
@copilot |
…o-op detector pattern Co-authored-by: nodece <16235121+nodece@users.noreply.github.com>
…ctor reconnect Co-authored-by: nodece <16235121+nodece@users.noreply.github.com>
Author
Done in commits 33e09e7 and 3891e64:
|
Co-authored-by: nodece <16235121+nodece@users.noreply.github.com>
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.
Problem
Consumers permanently stop receiving messages when topic ownership transfers (broker failover, unload) and the
CommandCloseConsumernotification fails to arrive due to network issues or broker crashes. Current connection-level ping-pong only validates TCP connectivity, not topic ownership.Changes
Core Implementation
PartitionConsumerIdleDetector: Tracks consumer activity (receive, ack, nack, redeliver) and triggers lookup when idle for 30s (configurable). Reconnects with cleanup if ownership changed.Configuration (
ConsumerConfigurationData)consumerIdleTimeoutMs(default: 30000, set to 0 to disable)Integration (
ConsumerImpl)internalReceive(),doAcknowledge(),negativeAcknowledge(),redeliverUnacknowledgedMessages()getUnAckedMessageTracker(),getAcknowledgmentsGroupingTracker(),incrementConsumerEpoch()Example Usage
Test Coverage
Original prompt
Add partition-level idle detection for consumer to prevent permanent message loss after topic ownership transfer
Problem
When topic ownership transfers (e.g., broker failover, topic unload), some partition consumers may permanently fail to receive messages because:
CommandCloseConsumernotificationImpact: Silent data loss, requires manual intervention, affects production availability
Solution
Implement partition-level idle detection + automatic reconnect mechanism in the consumer:
Key Features
internalReceive())doAcknowledge())negativeAcknowledge())Implementation Requirements
1. Create
PartitionConsumerIdleDetector.javaLocation:
pulsar-client/src/main/java/org/apache/pulsar/client/impl/PartitionConsumerIdleDetector.javaKey Methods:
markActive()- Called when consumer has activitycheckIdleAndReconnectIfNeeded()- Periodic check for idle stateverifyTopicOwnership()- Lookup to verify if broker changedreconnectWithCleanup()- Reconnect + cleanup logicCleanup Logic:
2. Modify
ConsumerImpl.javaAdd fields:
Integrate in constructor:
Add activity markers:
Expose helper methods (package-private for IdleDetector):
Clean up in closeAsync():
3. Modify
ConsumerConfigurationData.javaAdd configuration fields: