i3wangyi commented on a change in pull request #348: Adding the configuration
items of the WAGED rebalancer.
URL: https://github.com/apache/helix/pull/348#discussion_r307454764
##########
File path: helix-core/src/main/java/org/apache/helix/model/ClusterConfig.java
##########
@@ -657,6 +678,68 @@ public void enableP2PMessage(boolean enabled) {
_record.setBooleanField(HelixConfigProperty.P2P_MESSAGE_ENABLED.name(),
enabled);
}
+ /**
+ * Set the required Instance Capacity Keys.
+ * @param capacityKeys
+ */
+ public void setInstanceCapacityKeys(List<String> capacityKeys) {
+ if (capacityKeys == null || capacityKeys.isEmpty()) {
+ throw new IllegalArgumentException("The input instance capacity key list
is empty.");
+ }
+ _record.setListField(ClusterConfigProperty.INSTANCE_CAPACITY_KEYS.name(),
capacityKeys);
+ }
+
+ /**
+ * @return The required Instance Capacity Keys. If not configured, return an
empty list.
+ */
+ public List<String> getInstanceCapacityKeys() {
+ List<String> capacityKeys =
_record.getListField(ClusterConfigProperty.INSTANCE_CAPACITY_KEYS.name());
+ if (capacityKeys == null) {
+ return Collections.emptyList();
+ }
+ return capacityKeys;
+ }
+
+ /**
+ * Set the global rebalancer's assignment preference.
+ * @param preference A map of the GlobalRebalancePreferenceKey and the
corresponding weight.
+ * The ratio of the configured weights will determine the
rebalancer's behavior.
+ */
+ public void setGlobalRebalancePreference(Map<GlobalRebalancePreferenceKey,
Integer> preference) {
+ Map<String, String> preferenceMap = new HashMap<>();
+ for (GlobalRebalancePreferenceKey key : preference.keySet()) {
+ if (preference.get(key) > MAX_REBALANCE_PREFERENCE
+ || preference.get(key) < MIN_REBALANCE_PREFERENCE) {
+ throw new IllegalArgumentException(String
+ .format("Invalid global rebalance preference configuration. Key
%s, Value %d.",
+ key.name(), preference.get(key)));
+ }
+ preferenceMap.put(key.name(), Integer.toString(preference.get(key)));
+ }
+ _record.setMapField(ClusterConfigProperty.REBALANCE_PREFERENCE.name(),
preferenceMap);
+ }
+
+ /**
+ * Get the global rebalancer's assignment preference.
+ */
+ public Map<GlobalRebalancePreferenceKey, Integer>
getGlobalRebalancePreference() {
+ Map<String, String> preferenceStrMap =
+ _record.getMapField(ClusterConfigProperty.REBALANCE_PREFERENCE.name());
+ if (preferenceStrMap != null && !preferenceStrMap.isEmpty()) {
+ Map<GlobalRebalancePreferenceKey, Integer> preference = new HashMap<>();
Review comment:
Stream doesn't give you benefits in performance but fewer codes and better
readability. In this case, you can compare
```
if (preferenceStrMap.keySet()
.stream()
.anyMatch(key ->
EnumUtils.isValidEnum(GlobalRebalancePreferenceKey.class, key))) {
return DEFAULT_GLOBAL_REBALANCE_PREFERENCE;
} else {
return preferenceStrMap.entrySet()
.stream()
.collect(Collectors.toMap(e -> e.getKey(), e ->
Integer.parseInt(e.getValue()))
}
```
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services