-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix][broker] Align bundles logic in getNamespacePoliciesAsync with sync method #25158
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?
[fix][broker] Align bundles logic in getNamespacePoliciesAsync with sync method #25158
Conversation
6b586f1 to
f4bd3f6
Compare
f4bd3f6 to
24033ed
Compare
| } | ||
|
|
||
| @Test | ||
| public void testGetNamespacePoliciesSyncAsyncBundlesConsistency() throws Exception { |
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.
Did this test fail before making the change to production code? If not, I think that it would be more useful to verify that the behavior is correct for the async method regarding the modified detail.
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.
@lhotari Thanks for the feedback!
You're right—the current test would likely pass even before the change because LocalPolicies.bundles and NamespaceBundleFactory.getBundles() often return the same value in normal scenarios.
To address this, I'll update the test to explicitly verify that the bundles are retrieved via NamespaceBundleFactory. Would mocking NamespaceBundleFactory and verifying the call to getBundlesAsync() be the preferred approach here?
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.
I've updated the test to testGetNamespacePoliciesAsyncReflectsBundleSplit.
This test explicitly verifies that getPoliciesAsync returns the latest bundles from NamespaceBundleFactory after a bundle split:
- Create namespace with 1 bundle
- Split the bundle → 2 bundles
- Verify
getPoliciesAsync()returns 2 bundles
Before the fix: LocalPolicies.bundles would still show 1 bundle (stale data) → test fails
After the fix: NamespaceBundleFactory.getBundlesAsync() provides the latest 2 bundles → test passes
This approach verifies the actual behavior change rather than just comparing sync/async consistency, which would pass even before the fix.
@zooo-code the intention is that contributors would setup "Personal CI" so that they could run the Pulsar CI without dependency on apache/pulsar maintainers approving CI runs. |
Thanks for the pointer! I'll enable GitHub Actions on my forked repository right away to run the CI independently. |
0592a10 to
7164373
Compare
|
@lhotari Could you please approve the CI run? I fixed the checkstyle violations. |
@zooo-code As the first step, please enable Personal CI and complete a run in your fork by opening a PR for this same branch to your own forked repository. You will just need to enable GitHub Actions in your own repository before this. It's free. This will be helpful if you plan to make more contributions. There might be more CI failures and it's better that you can run CI on your own. Just be aware of many flaky tests in Pulsar. You can rerun failed build steps to get pass them. |
a46183a to
7164373
Compare
|
Hi @lhotari, I've refactored the code so that sync calls async as you suggested. However, I'm encountering a test failure in CI. Test failure:
Root cause: Possible solutions:
Could you advise on the preferred solution? Thanks! |
3d6f805 to
4673a80
Compare
|
Hi @lhotari I've refactored the code as suggested so that the sync method now calls the async one. However, I'm hitting a failure in It's caused by ContentDeserializationException: Failed to deserialize payload for key '/admin/local-policies/schematest/test'
Caused by: MismatchedInputException: No content to map due to end-of-inputThe refactoring exposed a pre-existing edge case. The original code likely handled data access differently, while the new async approach triggers full object deserialization, which fails on empty content. I tried catching Should I handle this at the |
4673a80 to
9977b76
Compare
9977b76 to
123c9c7
Compare
|
Hi @lhotari, I've resolved the Summary of Changes
Verification
Ready for review! |
Fixes #25128
Motivation
The logic for setting
policies.bundlesis different betweengetNamespacePolicies(sync) andgetNamespacePoliciesAsync:getNamespacePolicies(sync):NamespaceBundleFactory.getBundles().getBundlesData()bundleData != null ? bundleData : policies.bundlesfalsewhen LocalPolicies is absentgetNamespacePoliciesAsync:LocalPolicies.bundleslocalPolicies.isPresent())This inconsistency can cause different results when calling sync vs async methods for the same namespace.
Modifications
getNamespacePolicies(sync) to callgetNamespacePoliciesAsyncand wait for the result, eliminating code duplicationgetNamespacePoliciesAsyncnow usesNamespaceBundleFactory.getBundlesAsync()instead ofLocalPolicies.bundlesbundleData != null ? bundleData : policies.bundlesmigratedfield defaults tofalsewhen LocalPolicies is absentVerifying this change
Added testGetNamespacePoliciesSyncAsyncBundlesConsistency test in AdminApiTest to verify that sync (getPolicies) and async (getPoliciesAsync) methods return consistent bundles data.
Existing tests only verify sync getPolicies().bundles behavior (e.g., AdminApiTest:816,822,3223, NamespacesTest:1266). There was no test that verifies async getPoliciesAsync returns the same bundles data as sync method. This new test explicitly validates the consistency between sync and async methods, which is the core fix of this PR.
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: https://github.com/zooo-code/pulsar