sijie commented on a change in pull request #2618: Guard against NaN for double 
type metrics
URL: https://github.com/apache/incubator-pulsar/pull/2618#discussion_r219042150
 
 

 ##########
 File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/SimpleLoadManagerImpl.java
 ##########
 @@ -655,12 +655,12 @@ public void writeResourceQuotasToZooKeeper() throws 
Exception {
         // write the load factors
         
setDynamicConfigurationToZK(LOADBALANCER_DYNAMIC_SETTING_LOAD_FACTOR_CPU_ZPATH, 
new HashMap<String, String>() {
             {
-                put(SETTING_NAME_LOAD_FACTOR_CPU, 
Double.toString(realtimeCpuLoadFactor));
+                put(SETTING_NAME_LOAD_FACTOR_CPU, 
Double.isFinite(realtimeCpuLoadFactor) ? Double.toString(realtimeCpuLoadFactor) 
: Double.toString(0.0));
 
 Review comment:
   better to have a util function
   ```
   double getFiniteValue(double value, double defaultValue) {
       return Double.isFinite(value) ? value : defaultValue;
   }
   ```
   
   so you can call `Double.toString(getFiniteValue(realtimeCpuLoadFactor, 
0.0))`; and this util function can be reused 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to