Skip to content

Commit

Permalink
[fix][broker]fix the zero value as denominator cause ArithmeticExcept…
Browse files Browse the repository at this point in the history
…ion when selectBroker use LeastResourceUsageWithWeight (apache#16573)

* fix the zero value as denominator cause ArithmeticException

* fix the zero value as denominator cause ArithmeticException

Co-authored-by: nicklixinyang <[email protected]>
  • Loading branch information
Nicklee007 and nicklixinyang authored Aug 1, 2022
1 parent 0c1b3de commit 99fbe22
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ private double updateAndGetMaxResourceUsageWithWeight(String broker, BrokerData
@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.
Expand All @@ -151,12 +156,6 @@ public Optional<String> selectBroker(Set<String> candidates, BundleData bundleTo
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);
Expand Down

0 comments on commit 99fbe22

Please sign in to comment.