Meet0861 opened a new pull request, #24759:
URL: https://github.com/apache/pulsar/pull/24759

   Fixes: [#24754](https://github.com/apache/pulsar/issues/24754)
   
   
   ### Motivation
   
   The topK bundle selection fails due to the sorting failure in the partition 
sort algo being used 
[here](https://github.com/apache/pulsar/blob/437d9f6a3ccfdfd327ac032c298728fcc43fc263/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/models/TopKBundles.java#L115).
   Partition sort uses, NamespaceBundleStats' + BundleData's custom 
ccompararable implementations where it checks throughput, connections, cache 
size etc against the defined threshold and when values are within the defined 
thresholds, they are considered "equal" (return 0), but this creates 
transitivity violations.
   It violates the transitivity property required by Java's Comparable 
interface, causing 
[Collections.sort()](https://github.com/apache/pulsar/blob/437d9f6a3ccfdfd327ac032c298728fcc43fc263/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/models/TopKBundles.java#L148)
 to potentially throw IllegalArgumentException with "Comparison method violates 
its general contract" error.
   Error Log:
   `2025-09-12T22:29:58.832386492+05:30 16:59:58.832 [pulsar-load-manager-1-1] 
WARN  org.apache.pulsar.broker.loadbalance.LoadResourceQuotaUpdaterTask - Error 
write resource quota - java.lang.IllegalArgumentException: Comparison method 
violates its general contract`
   
   Due to this failure, the job - writeBundleDataOnZooKeeper(leader broker 
writes bundle data aggregated from all brokers to metadata store) in 
modularLoadManager may fail 
[link](https://github.com/apache/pulsar/blob/437d9f6a3ccfdfd327ac032c298728fcc43fc263/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java#L1173)
 and can cause degradation in productions due to failure/inconsistencies in LB 
decisions
   
   ### Modifications
   
   added strict NamespaceBundleStats comparator and BundleData comparator to be 
used for sorting for topk bundle comparison which is being used by 
ModularLoadManager and ExtensibleLoadManager
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   This change added tests and can be verified as follows:
     - *Added unit tests to validate the fix*
   
   ### Does this pull request potentially affect one of the following parts:
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   *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
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   - [ ] `doc` <!-- Your PR contains doc changes. -->
   - [ ] `doc-required` <!-- Your PR changes impact docs and you will update 
later -->
   - [ *] `doc-not-needed` <!-- Your PR changes do not impact docs -->
   - [ ] `doc-complete` <!-- Docs have been already added -->
   
   ### Matching PR in forked repository
   
   PR in forked repository: 
https://github.com/Meet0861/pulsar/tree/fix-transitivityViolationInNamespaceBundleStatsAndBundledataComparator
   
   <!--
   After opening this PR, the build in apache/pulsar will fail and instructions 
will
   be provided for opening a PR in the PR author's forked repository.
   
   apache/pulsar pull requests should be first tested in your own fork since 
the 
   apache/pulsar CI based on GitHub Actions has constrained resources and quota.
   GitHub Actions provides separate quota for pull requests that are executed 
in 
   a forked repository.
   
   The tests will be run in the forked repository until all PR review comments 
have
   been handled, the tests pass and the PR is approved by a reviewer.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to