This is an automated email from the ASF dual-hosted git repository.
zhangmingao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 99fbe2226fe [fix][broker]fix the zero value as denominator cause
ArithmeticException when selectBroker use LeastResourceUsageWithWeight (#16573)
99fbe2226fe is described below
commit 99fbe2226fe8ace44eea0899292833376d86fc20
Author: lixinyang <[email protected]>
AuthorDate: Mon Aug 1 14:48:46 2022 +0800
[fix][broker]fix the zero value as denominator cause ArithmeticException
when selectBroker use LeastResourceUsageWithWeight (#16573)
* fix the zero value as denominator cause ArithmeticException
* fix the zero value as denominator cause ArithmeticException
Co-authored-by: nicklixinyang <[email protected]>
---
.../broker/loadbalance/impl/LeastResourceUsageWithWeight.java | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/LeastResourceUsageWithWeight.java
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/LeastResourceUsageWithWeight.java
index 721917cb73d..2e717500e64 100644
---
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/LeastResourceUsageWithWeight.java
+++
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/LeastResourceUsageWithWeight.java
@@ -125,6 +125,11 @@ public class LeastResourceUsageWithWeight implements
ModularLoadManagerStrategy
@Override
public Optional<String> selectBroker(Set<String> candidates, BundleData
bundleToAssign, LoadData loadData,
ServiceConfiguration conf) {
+ if (candidates.isEmpty()) {
+ log.info("There are no available brokers as candidates at this
point for bundle: {}", bundleToAssign);
+ return Optional.empty();
+ }
+
bestBrokers.clear();
// Maintain of list of all the best scoring brokers and then randomly
// select one of them at the end.
@@ -151,12 +156,6 @@ public class LeastResourceUsageWithWeight implements
ModularLoadManagerStrategy
bestBrokers.addAll(candidates);
}
- if (bestBrokers.isEmpty()) {
- // If still, it means there are no available brokers at this point.
- log.error("There are no available brokers as candidates at this
point for bundle: {}", bundleToAssign);
- return Optional.empty();
- }
-
if (log.isDebugEnabled()) {
log.debug("Selected {} best brokers: {} from candidate brokers:
{}", bestBrokers.size(), bestBrokers,
candidates);