You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@helix.apache.org by GitBox <gi...@apache.org> on 2019/08/19 22:30:25 UTC

[GitHub] [helix] i3wangyi commented on a change in pull request #422: Redefine the hard/soft constraints

i3wangyi commented on a change in pull request #422: Redefine the hard/soft constraints
URL: https://github.com/apache/helix/pull/422#discussion_r315439144
 
 

 ##########
 File path: helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/constraints/SoftConstraintWeightModel.java
 ##########
 @@ -0,0 +1,47 @@
+package org.apache.helix.controller.rebalancer.waged.constraints;
+
+import java.util.Map;
+
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * The class retrieves the offline model that defines the relative importance of soft constraints.
+ */
+public class SoftConstraintWeightModel {
+  private float MIN_SCORE = -1000.0f;
+  private float MAX_SCORE = 1000.0f;
+  private static Map<SoftConstraint.Type, Float> MODEL;
+
+  static {
+    // TODO either define the weights in property files or zookeeper node or static human input
+    MODEL = ImmutableMap.<SoftConstraint.Type, Float> builder()
+        .put(SoftConstraint.Type.LEAST_MOVEMENTS, 1.0f)
+        .put(SoftConstraint.Type.LEAST_PARTITION_COUNT, 1.0f)
+        .put(SoftConstraint.Type.LEAST_USED_NODE, 1.0f).build();
+  }
+
+  interface ScoreScaler {
+    /**
+     * Method to scale the origin score to a normalized range
+     * @param originScore The origin score of a range
+     * @return The normalized value between 0 - 1
+     */
+    float scale(float originScore);
+  }
+
+  private ScoreScaler MIN_MAX_SCALER =
+      originScore -> (originScore - MIN_SCORE) / (MAX_SCORE - MIN_SCORE);
+
+  /**
+   * Given the calculated scores map by soft constraints, get the sum of scores
+   * @param originScoresMap The origin scores of soft constraints
+   * @return The sum of double type
+   */
+  public double sumOfScores(Map<SoftConstraint, Float> originScoresMap) {
+    return originScoresMap.entrySet().stream().map(constraintToOriginScore -> {
+      float score = MIN_MAX_SCALER.scale(constraintToOriginScore.getValue());
+      float weight = MODEL.getOrDefault(constraintToOriginScore.getKey().getType(), 0f);
 
 Review comment:
   The MODEL is defined statically and not set dynamically on the fly. I think we should assume all types have a valid value or we're doing a bad job when assigning the weight.  Throw exception will fail all the rest operations I don't think it's good idea

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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