-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix][broker] Ensure KeyShared sticky mode consumer respects assigned ranges #24730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
/pulsarbot rerun-failure-checks |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #24730 +/- ##
============================================
- Coverage 74.21% 74.17% -0.04%
- Complexity 33463 33604 +141
============================================
Files 1895 1900 +5
Lines 147954 148401 +447
Branches 17130 17206 +76
============================================
+ Hits 109805 110082 +277
- Misses 29387 29539 +152
- Partials 8762 8780 +18
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a critical bug in the KeyShared sticky mode consumer where it incorrectly consumed messages from hash ranges not explicitly assigned to it. The issue was that non-contiguous sticky ranges would cause consumers to receive messages from gaps between their assigned ranges.
Key changes:
- Refactored the
rangeMapdata structure to store complete Range objects instead of just start/end points - Enhanced conflict detection algorithm for better accuracy in detecting range overlaps
- Added comprehensive validation for consumer's own ranges to prevent internal conflicts
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| HashRangeExclusiveStickyKeyConsumerSelector.java | Core fix - refactored data structure and algorithms for precise range handling |
| HashRangeExclusiveStickyKeyConsumerSelectorTest.java | Updated unit tests to verify the fix and added new test cases |
| KeySharedSubscriptionTest.java | Added integration test to verify end-to-end behavior |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
.../main/java/org/apache/pulsar/broker/service/HashRangeExclusiveStickyKeyConsumerSelector.java
Show resolved
Hide resolved
pulsar-broker/src/test/java/org/apache/pulsar/client/api/KeySharedSubscriptionTest.java
Show resolved
Hide resolved
.../main/java/org/apache/pulsar/broker/service/HashRangeExclusiveStickyKeyConsumerSelector.java
Show resolved
Hide resolved
.../main/java/org/apache/pulsar/broker/service/HashRangeExclusiveStickyKeyConsumerSelector.java
Show resolved
Hide resolved
.../main/java/org/apache/pulsar/broker/service/HashRangeExclusiveStickyKeyConsumerSelector.java
Show resolved
Hide resolved
lhotari
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @shibd! A few minor comments. I guess checking whether overlapped ranges at the boundary are allowed or not is something to test and check the backwards compatibility. That was already pointed by @poorbarcode in a previous comment.
.../main/java/org/apache/pulsar/broker/service/HashRangeExclusiveStickyKeyConsumerSelector.java
Outdated
Show resolved
Hide resolved
...t/java/org/apache/pulsar/broker/service/HashRangeExclusiveStickyKeyConsumerSelectorTest.java
Outdated
Show resolved
Hide resolved
...t/java/org/apache/pulsar/broker/service/HashRangeExclusiveStickyKeyConsumerSelectorTest.java
Outdated
Show resolved
Hide resolved
lhotari
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, great job @shibd
… ranges (apache#24730) (cherry picked from commit e73532a)
… ranges (apache#24730) (cherry picked from commit e73532a) (cherry picked from commit 86502cf)
… ranges (apache#24730) (cherry picked from commit e73532a) (cherry picked from commit 86502cf)
… ranges (apache#24730) (cherry picked from commit e73532a) (cherry picked from commit 712b2a8)
… ranges (apache#24730) (cherry picked from commit e73532a) (cherry picked from commit 712b2a8)
Motivation
This PR fixes a critical bug where the
KeySharedsticky mode consumer in Pulsar would incorrectly consume messages from hash ranges not explicitly assigned to it.Specifically, if a single
KeySharedconsumer is configured with non-contiguous sticky ranges, e.g.:[0, 9999][20000, 29999][40000, 49999]The consumer would incorrectly receive messages for keys falling into the gaps (e.g.,
15000which is between9999and20000).The root cause lies in the
HashRangeExclusiveStickyKeyConsumerSelector'sselectmethod, which previously stored only the start/end points of ranges in itsrangeMap. This led to an erroneous interpretation where any hash between a range'sendand the next range'sstartwould be assigned to the previous range's consumer.pulsar/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/HashRangeExclusiveStickyKeyConsumerSelector.java
Lines 108 to 116 in 84b834f
In the scenario above, this consumer would actually receive messages in the range of 0 ~ 49999 (when there is only one consumer).
You can reproduce by testing from this PR:
testConsumerSelectWithMultipRangesunit test in this PR.testCustomStickyRangeintegration test in this PR.BTW: v3.0 has the same issue.
Modifications
Verifying this change
This change added new unit tests and an integration test and can be verified as follows:
HashRangeExclusiveStickyKeyConsumerSelectorTest(Unit Tests):testConsumerSelect: Updated to verifyselect(hash)returns the correct consumer only whenhashis within an explicitly defined range, andnullfor hashes in gaps.testConsumerSelectWithMultipRanges: Added to confirm a single consumer with multiple distinct sticky ranges correctly selects messages only within those ranges and returnsnullfor hashes in gaps.testOneConsumerRangeConflict: Added to verify that a consumer cannot be added if its ownKeySharedMetacontains internally conflicting or invalid (start > end) ranges.testSingleRangeConflictandtestMultipleRangeConflict: Updated to correctly assert expected conflicts and non-conflicts based on the new strict range overlap detection logic.KeySharedSubscriptionTest.testCustomStickyRange(Integration Test):Documentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: ```