[improve][broker] Replace isServiceUnitActiveAsync with checkTopicNsOwnership#24780
Merged
BewareMyPower merged 1 commit intoSep 25, 2025
Conversation
BewareMyPower
requested review from
Demogorgon314,
Technoboy-,
codelipenghui,
lhotari,
nodece,
poorbarcode and
shibd
September 25, 2025 04:57
BewareMyPower
force-pushed
the
bewaremypower/ownership-check-cleanup
branch
from
September 25, 2025 05:02
da543d0 to
03ee056
Compare
Demogorgon314
approved these changes
Sep 25, 2025
4 tasks
lhotari
approved these changes
Sep 25, 2025
lhotari
left a comment
Member
There was a problem hiding this comment.
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:
|
nodece
approved these changes
Sep 25, 2025
walkinggo
pushed a commit
to walkinggo/pulsar
that referenced
this pull request
Oct 8, 2025
manas-ctds
pushed a commit
to datastax/pulsar
that referenced
this pull request
Oct 15, 2025
…wnership (apache#24780) (cherry picked from commit 46a76e9) (cherry picked from commit 05d88f7)
srinath-ctds
pushed a commit
to datastax/pulsar
that referenced
this pull request
Nov 6, 2025
…wnership (apache#24780) (cherry picked from commit 46a76e9) (cherry picked from commit 05d88f7)
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.
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: