narendly commented on a change in pull request #511: More strict partition 
weight validation while creating the cluster model.
URL: https://github.com/apache/helix/pull/511#discussion_r336166711
 
 

 ##########
 File path: helix-core/src/main/java/org/apache/helix/model/ClusterConfig.java
 ##########
 @@ -705,49 +706,78 @@ public void setInstanceCapacityKeys(List<String> 
capacityKeys) {
 
   /**
    * Get the default instance capacity information from the map fields.
+   *
    * @return data map if it exists, or empty map
    */
   public Map<String, Integer> getDefaultInstanceCapacityMap() {
-    Map<String, String> capacityData =
-        
_record.getMapField(ClusterConfigProperty.DEFAULT_INSTANCE_CAPACITY_MAP.name());
-
-    if (capacityData != null) {
-      return capacityData.entrySet().stream().collect(
-          Collectors.toMap(entry -> entry.getKey(), entry -> 
Integer.parseInt(entry.getValue())));
-    }
-    return Collections.emptyMap();
+    return 
getDefaultCapacityMap(ClusterConfigProperty.DEFAULT_INSTANCE_CAPACITY_MAP);
   }
 
   /**
    * Set the default instance capacity information with an Integer mapping.
+   * This information is required by the global rebalancer.
+   * @see <a href="Rebalance Algorithm">
+   * 
https://github.com/apache/helix/wiki/Design-Proposal---Weight-Aware-Globally-Even-Distribute-Rebalancer#rebalance-algorithm-adapter
+   * </a>
+   * If the instance capacity is not configured in either Instance Config nor 
Cluster Config, the
+   * cluster topology is considered invalid. So the rebalancer may stop 
working.
    * @param capacityDataMap - map of instance capacity data
    * @throws IllegalArgumentException - when any of the data value is a 
negative number or when the map is empty
+   */
+  public void setDefaultInstanceCapacityMap(Map<String, Integer> 
capacityDataMap)
+      throws IllegalArgumentException {
+    setDefaultCapacityMap(ClusterConfigProperty.DEFAULT_INSTANCE_CAPACITY_MAP, 
capacityDataMap);
+  }
+
+  /**
+   * Get the default partition weight information from the map fields.
    *
+   * @return data map if it exists, or empty map
+   */
+  public Map<String, Integer> getDefaultPartitionWeightMap() {
+    return 
getDefaultCapacityMap(ClusterConfigProperty.DEFAULT_PARTITION_WEIGHT_MAP);
+  }
+
+  /**
+   * Set the default partition weight information with an Integer mapping.
    * This information is required by the global rebalancer.
    * @see <a href="Rebalance Algorithm">
-   *   
https://github.com/apache/helix/wiki/Design-Proposal---Weight-Aware-Globally-Even-Distribute-Rebalancer#rebalance-algorithm-adapter
-   *   </a>
-   * If the instance capacity is not configured in neither Instance Config nor 
Cluster Config, the
+   * 
https://github.com/apache/helix/wiki/Design-Proposal---Weight-Aware-Globally-Even-Distribute-Rebalancer#rebalance-algorithm-adapter
+   * </a>
+   * If the partition weight is not configured in either Resource Config nor 
Cluster Config, the
    * cluster topology is considered invalid. So the rebalancer may stop 
working.
+   * @param weightDataMap - map of partition weight data
+   * @throws IllegalArgumentException - when any of the data value is a 
negative number or when the map is empty
    */
-  public void setDefaultInstanceCapacityMap(Map<String, Integer> 
capacityDataMap)
+  public void setDefaultPartitionWeightMap(Map<String, Integer> weightDataMap)
       throws IllegalArgumentException {
-    if (capacityDataMap == null || capacityDataMap.size() == 0) {
-      throw new IllegalArgumentException("Default Instance Capacity Data is 
empty");
-    }
+    setDefaultCapacityMap(ClusterConfigProperty.DEFAULT_PARTITION_WEIGHT_MAP, 
weightDataMap);
+  }
 
-    Map<String, String> capacityData = new HashMap<>();
+  private Map<String, Integer> getDefaultCapacityMap(ClusterConfigProperty 
capacityPropertyType) {
+    Map<String, String> capacityData = 
_record.getMapField(capacityPropertyType.name());
+    if (capacityData != null) {
+      return capacityData.entrySet().stream().collect(
+          Collectors.toMap(entry -> entry.getKey(), entry -> 
Integer.parseInt(entry.getValue())));
+    }
+    return Collections.emptyMap();
+  }
 
+  public void setDefaultCapacityMap(ClusterConfigProperty capacityPropertyType,
+      Map<String, Integer> capacityDataMap) throws IllegalArgumentException {
+    if (capacityDataMap == null || capacityDataMap.size() == 0) {
+      throw new IllegalArgumentException("Default capacity data is empty");
 
 Review comment:
   `capacityDataMap.size() == 0`
   
   I think this might actually be a valid thing for users to do, so we 
shouldn't throw an exception? Are they not allowed to empty out the default 
capacity map? They should be allowed to for stricter capacity planning, correct?
   
   Or we provide a separate method for `reset/removeDefaultCapacityMap`?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@helix.apache.org
For additional commands, e-mail: reviews-h...@helix.apache.org

Reply via email to