-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[improve][broker] Replace isServiceUnitActiveAsync with checkTopicNsOwnership #24780
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
[improve][broker] Replace isServiceUnitActiveAsync with checkTopicNsOwnership #24780
Conversation
da543d0 to
03ee056
Compare
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, thanks for taking actions to cleanup Pulsar code!
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #24780 +/- ##
============================================
- Coverage 74.23% 74.15% -0.09%
- Complexity 33271 33601 +330
============================================
Files 1904 1905 +1
Lines 148507 148571 +64
Branches 17214 17226 +12
============================================
- Hits 110246 110166 -80
- Misses 29484 29588 +104
- Partials 8777 8817 +40
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
…wnership (apache#24780) (cherry picked from commit 46a76e9) (cherry picked from commit 05d88f7)
…wnership (apache#24780) (cherry picked from commit 46a76e9) (cherry picked from commit 05d88f7)
Motivation
I'm working on optimizing the long topic loading path recently and I found these two methods just work the same. The ownership validation does not have a single source of truth, which makes code hard to read.
BrokerService#checkTopicNsOwnershipThis method returns a void future that fails if the topic is not owned by the current broker. It's called by:
TransactionMetadataStoreService#handleTcClientConnectAbstractTopic#addProducerBrokerService#createNonPersistentTopicBrokerService#loadOrCreatePersistentTopicBrokerService#createPendingLoadTopicNonPersistentTopic#checkTopicNsOwnershipPersistentTopic#internalSubscribeNamespaceService#isServiceUnitActiveAsyncThis method returns a boolean future that returns false if the topic is not owned by the current broker. It's only used in
BrokerService#checkOwnershipAndCreatePersistentTopic.The implementations of these two methods are slightly different, which might also mislead users that they are different.
Here is how
isServiceUnitActiveAsynchandles topics' bundle:pulsar/pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceService.java
Lines 1249 to 1253 in 1b74fe0
However, the logic is duplicated with
pulsar/pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/OwnershipCache.java
Lines 147 to 153 in 1b74fe0
pulsar/pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceService.java
Lines 1280 to 1286 in 1b74fe0
which is called by
checkTopicNsOwnership:pulsar/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java
Line 2376 in 1b74fe0
The only place that calls
isServiceUnitActiveAsyncis here:pulsar/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java
Line 1739 in 1b74fe0
when it returns false, it just completes another future exceptionally:
pulsar/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java
Lines 1761 to 1764 in 1b74fe0
where the error message does not have bundle info included like
checkTopicNsOwnership.Modifications
Use
checkTopicNsOwnershipinstead ofisServiceUnitActiveAsyncinBrokerService#checkOwnershipAndCreatePersistentTopic.Remove the
isServiceUnitActiveAsyncandisServiceUnitActivemethods fromNamespaceService. The same function can be implemented easily by composing existing methods like:Verifying this change
This change is a trivial rework / code cleanup without any test coverage.
Documentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: