You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "Meet0861 (via GitHub)" <gi...@apache.org> on 2025/09/18 07:20:31 UTC

[PR] [fix][broker] transitivity violation during bundle comparison in topK bundles by NamespaceBundleStats,BundleData Comparator [pulsar]

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-unsubscribe@pulsar.apache.org

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


Re: [PR] [fix][broker] transitivity violation during bundle comparison in topK bundles by NamespaceBundleStats,BundleData Comparator [pulsar]

Posted by "merlimat (via GitHub)" <gi...@apache.org>.
merlimat commented on PR #24759:
URL: https://github.com/apache/pulsar/pull/24759#issuecomment-6179032626

   Thanks for working on this. The issue this PR addresses (#24754) was fixed by #24772, so I'm closing this one as superseded. If part of this change is still needed, feel free to reopen it or open a new PR against the current master. This is part of the open-PR cleanup discussed on dev@pulsar.apache.org.


-- 
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-unsubscribe@pulsar.apache.org

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


Re: [PR] [fix][broker] transitivity violation during bundle comparison in topK bundles by NamespaceBundleStats,BundleData Comparator [pulsar]

Posted by "merlimat (via GitHub)" <gi...@apache.org>.
merlimat closed pull request #24759: [fix][broker] transitivity violation during bundle comparison in topK bundles by NamespaceBundleStats,BundleData Comparator
URL: https://github.com/apache/pulsar/pull/24759


-- 
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-unsubscribe@pulsar.apache.org

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


Re: [PR] [fix][broker] transitivity violation during bundle comparison in topK bundles by NamespaceBundleStats,BundleData Comparator [pulsar]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #24759:
URL: https://github.com/apache/pulsar/pull/24759#issuecomment-3305780582

   @Meet0861 Please add the following content to your PR description and select a checkbox:
   ```
   - [ ] `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 -->
   ```


-- 
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-unsubscribe@pulsar.apache.org

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


Re: [PR] [fix][broker] transitivity violation during bundle comparison in topK bundles by NamespaceBundleStats,BundleData Comparator [pulsar]

Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on PR #24759:
URL: https://github.com/apache/pulsar/pull/24759#issuecomment-3307002362

   @Meet0861 Pull requests should target the master branch. I changed the base, but that messed up things. You can rebase on your side and do a force-push


-- 
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-unsubscribe@pulsar.apache.org

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


Re: [PR] [fix][broker] transitivity violation during bundle comparison in topK bundles by NamespaceBundleStats,BundleData Comparator [pulsar]

Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on PR #24759:
URL: https://github.com/apache/pulsar/pull/24759#issuecomment-3322620545

   @Meet0861 Thanks for the effort of debugging and drilling down to the root cause.
   Since the compareTo contracts were violated in NamespaceBundleStats, TimeAverageMessageData and ResourceUnitRanking classes, I have addressed those in an alternative approach to address the issue, #24772. It wouldn't have been useful to keep the invalid implementations since they could have caused similar problems in the future when sorting would have been used. The main purpose of `compareTo` methods is sorting.
   The original reason for the `Math.abs` was to compare with a coarse granularity (or resolution). I have addressed that without `Math.abs` in the PR so that the value is divided by the comparison resolution/granularity at comparison. The behavior isn't exactly the same as `Math.abs`, but it does retain the behavior of comparing at the desired level of granularity.
   Since the `compareTo` methods are now fixed with #24772, it won't be necessary to have custom comparators that this PR provides.


-- 
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-unsubscribe@pulsar.apache.org

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