-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix][broker] Avoid split non-existent bundle #25031
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
base: master
Are you sure you want to change the base?
Conversation
|
@coderzc Please add the following content to your PR description and select a checkbox: |
...r-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java
Outdated
Show resolved
Hide resolved
e2b577f to
2da2096
Compare
2da2096 to
d582d6b
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #25031 +/- ##
============================================
+ Coverage 74.35% 74.47% +0.11%
+ Complexity 34102 34037 -65
============================================
Files 1920 1899 -21
Lines 150313 149641 -672
Branches 17459 17397 -62
============================================
- Hits 111771 111448 -323
+ Misses 29635 29320 -315
+ Partials 8907 8873 -34
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
| return future; | ||
| } | ||
|
|
||
| public boolean checkBundleDataExistInNamespaceBundles(NamespaceBundles namespaceBundles, String bundleRange) { |
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.
@coderzc What is the difference between the behavior here and org.apache.pulsar.common.naming.NamespaceBundles#validateBundle?
By the way, this should be a private method?
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.
The behavior is almost the same, but validateBundle directly throws an exception instead of returning a result. I modified it to call validateBundle in checkBundleDataExistInNamespaceBundles.
f4ddc6f to
ef61623
Compare
| } | ||
| } finally { | ||
| lock.unlock(); | ||
| // lock.unlock(); |
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.
This should not be modified. Small problem.
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 race condition where namespace bundles could be split multiple times, causing failures on subsequent split attempts after the bundle has already been removed. The fix adds validation to check if a bundle still exists in the current NamespaceBundles before attempting to split it.
Key Changes:
- Added validation logic to skip splitting bundles that no longer exist in NamespaceBundles
- Changed validateBundle exception signature from generic Exception to more specific IllegalArgumentException
- Added test case to verify repeated split attempts don't cause errors
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| ModularLoadManagerImpl.java | Added checkBundleDataExistInNamespaceBundles method to validate bundle existence before split; commented out lock statements in writeBrokerDataOnZooKeeper |
| NamespaceBundles.java | Changed validateBundle to throw IllegalArgumentException instead of generic Exception for better type safety |
| ModularLoadManagerImplTest.java | Added testRepeatSplitBundle test to verify the fix for repeated bundle split attempts |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| pulsarClient.newConsumer().topic(topicNameI) | ||
| .subscriptionName("my-subscriber-name2").subscribe(); |
Copilot
AI
Jan 7, 2026
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.
The test creates consumers but never closes them, which can lead to resource leaks. Each consumer created in the loop should be closed after use, or stored in a list and closed in a cleanup step.
| primaryLoadManager.updateAll(); | ||
|
|
||
| primaryLoadManager.updateAll(); | ||
| Assert.assertFalse(loadData.getBundleData().containsKey(bundleKey)); |
Copilot
AI
Jan 7, 2026
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.
The test name 'testRepeatSplitBundle' and the setup with updateAll() called twice suggests this test should verify that repeated splits don't cause errors. However, the test only asserts that the bundle data was removed (line 1176), but doesn't verify that no exceptions were thrown during the second updateAll() call. Consider adding assertions to verify that both updateAll() calls complete successfully without throwing the PreconditionFailedException mentioned in the PR description.
Motivation
As you can see from the log, after
0x80000000_0xc0000000was successfully split, it was split again for the second time calling the updateAll() method and failed to split old bundle since bundle been deleted.Modifications
Skip split the bundles that do not exist in NamespaceBundles
Verifying this change
(Please pick either of the following options)
This change is a trivial rework / code cleanup without any test coverage.
(or)
This change is already covered by existing tests, such as (please describe tests).
(or)
This change added tests and can be verified as follows:
(example:)
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: