pulsar
pulsar copied to clipboard
[fix][broker] Key_Shared subscription: Reject consumers with incompatible policy
Fixes #23272
Motivation
When a consumer with a different Key_Shared policy connects, the current behavior is that the existing consumer will be closed and replaced with the consumer with the different policy. Since the replaced consumer gets disconnected, it will connect again and swap with the other consumer, and this replacement loop keeps going on.
Taken from #23272 by @lhotari:
When multiple consumers are using different policies, this should be properly handled. One possibility is to keep the policy of the connected consumers and reject any other consumers and return a proper error message.
Modifications
- Updated PersistentSubscription and NonPersistentSubscription behavior to reject new Key_Shared consumers (added to a Key_Shared subscription) when the new consumer's policy is incompatible with the dispatcher's policy. This is the case if the Key_Shared mode (AUTO_SPLIT/STICKY) or allowOutOfOrderDelivery (true/false) differs.
Verifying this change
- [x] Make sure that the change passes the CI checks.
This change added tests and can be verified as follows:
- Added unit test to PersistentSubscriptionTest that verifies that incompatible Key_Shared consumers are rejected by a persistent subscription.
- Added new unit test NonPersistentSubscriptionTest that verifies the same but for nonpersistent subscriptions.
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
- [ ] Dependencies (add or upgrade a dependency)
- [ ] The public API
- [ ] The schema
- [ ] The default values of configurations
- [ ] The threading model
- [ ] The binary protocol
- [ ] The REST endpoints
- [ ] The admin CLI options
- [ ] The metrics
- [ ] Anything that affects deployment
Documentation
- [ ]
doc
- [ ]
doc-required
- [x]
doc-not-needed
- [ ]
doc-complete
Matching PR in forked repository
PR in forked repository: https://github.com/pdolif/pulsar/pull/4