Skip to content

Commit

Permalink
fix edge case that breaches both max and decimal places
Browse files Browse the repository at this point in the history
  • Loading branch information
bohhyang committed Oct 29, 2024
1 parent e719789 commit 6b0f02d
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ public ZooKeeperAnnouncer(LoadBalancerServer server, boolean initialIsUp,
_warmupDuration = warmupDuration;
_executorService = executorService;
_eventEmitter = eventEmitter;

// take in max weight as a string to be precise at decimal places when creating a BigDecimal.
_maxWeight = maxWeight == null ? null : new BigDecimal(maxWeight);
if (actOnWeightBreach != null)
{
Expand Down Expand Up @@ -873,6 +875,7 @@ private Map<Integer, PartitionData> validatePartitionData(Map<Integer, Partition
throw getMaxWeightBreachException(weight, entry.getKey());
case RECTIFY:
entry.setValue(new PartitionData(_maxWeight.intValue()));
weight = _maxWeight;
_log.warn("Capped weight {} in Partition {} to the max weight allowed: {}.", weight.doubleValue(),
entry.getKey(), _maxWeight.intValue());
break;
Expand Down

0 comments on commit 6b0f02d

Please sign in to comment.