jiajunwang commented on a change in pull request #450: Implement one of the 
soft constraints
URL: https://github.com/apache/helix/pull/450#discussion_r321905393
 
 

 ##########
 File path: 
helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/constraints/InstancePartitionsCountConstraint.java
 ##########
 @@ -0,0 +1,55 @@
+package org.apache.helix.controller.rebalancer.waged.constraints;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.helix.controller.rebalancer.waged.model.AssignableNode;
+import org.apache.helix.controller.rebalancer.waged.model.AssignableReplica;
+import org.apache.helix.controller.rebalancer.waged.model.ClusterContext;
+
+
+/**
+ * Evaluate by instance's current partition count and estimated max partition 
count
+ */
+class InstancePartitionsCountConstraint extends SoftConstraint {
+
+  InstancePartitionsCountConstraint() {
+  }
+
+  InstancePartitionsCountConstraint(float maxScore, float minScore) {
+    super(maxScore, minScore);
+  }
+
+  @Override
+  float evaluateAssignment(AssignableNode node, AssignableReplica replica, 
ClusterContext clusterContext) {
+    int estimatedMaxPartitionCount = 
clusterContext.getEstimatedMaxPartitionCount();
+    int currentPartitionCount = node.getAssignedReplicaCount();
+    // When the node is idle, return with the maxScore.
+    if (currentPartitionCount == 0) {
+      return getMaxScore();
+    }
+    //When the node usage reaches the estimated max partition, return minimal 
score
+    if (currentPartitionCount >= estimatedMaxPartitionCount) {
 
 Review comment:
   That was a typo. should be (current - min) / 2 + min. But what I meant to 
say is more than this. Note the current count is hard limited by the hard 
constraint. Which could be much larger than estimatedMaxPartitionCount. It is 
up to you whether we want to score the larger count differently or not. 
Although I strongly suggest doing so.
   
   Otherwise, at some point, if all nodes have partition count more than the 
estimatedMaxPartitionCount, this soft constraint will lose the capability to 
evaluate reasonablly.

----------------------------------------------------------------
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