dasahcc commented on a change in pull request #1078:
URL: https://github.com/apache/helix/pull/1078#discussion_r442418714
##########
File path:
helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/constraints/PartitionMovementConstraint.java
##########
@@ -40,31 +40,53 @@
class PartitionMovementConstraint extends SoftConstraint {
private static final double MAX_SCORE = 1f;
private static final double MIN_SCORE = 0f;
- //TODO: these factors will be tuned based on user's preference
- // This factor indicates the default score that is evaluated if only
partition allocation matches
- // (states are different).
- private static final double ALLOCATION_MATCH_FACTOR = 0.5;
+ // The scale factor to adjust score when the proposed allocation partially
matches the assignment
+ // plan but will require a state transition (with partition movement).
+ // TODO: these factors will be tuned based on user's preference
+ private static final double STATE_TRANSITION_COST_FACTOR = 0.5;
+ private static final double MOVEMENT_COST_FACTOR = 0.25;
PartitionMovementConstraint() {
super(MAX_SCORE, MIN_SCORE);
}
+ /**
+ * @return 1 if the proposed assignment completely matches the previous best
possible assignment
+ * (or baseline assignment if the replica is newly added).
+ * STATE_TRANSITION_COST_FACTOR if the proposed assignment's
allocation matches the
+ * previous Best Possible assignment (or baseline assignment if the
replica is newly
+ * added) but state does not match.
+ * MOVEMENT_COST_FACTOR if the proposed assignment's allocation
matches the baseline
+ * assignment only, but not matches the previous best possible
assignment.
+ * 0 if the proposed assignment is a pure random movement.
+ */
@Override
protected double getAssignmentScore(AssignableNode node, AssignableReplica
replica,
ClusterContext clusterContext) {
- // Prioritize the previous Best Possible assignment
Map<String, String> bestPossibleAssignment =
getStateMap(replica, clusterContext.getBestPossibleAssignment());
- if (!bestPossibleAssignment.isEmpty()) {
- return calculateAssignmentScale(node, replica, bestPossibleAssignment);
- }
- // else, compare the baseline only if the best possible assignment does
not contain the replica
Map<String, String> baselineAssignment =
getStateMap(replica, clusterContext.getBaselineAssignment());
- if (!baselineAssignment.isEmpty()) {
- return calculateAssignmentScale(node, replica, baselineAssignment);
+ String nodeName = node.getInstanceName();
+ String state = replica.getReplicaState();
+
+ if (bestPossibleAssignment.isEmpty()) {
+ // If bestPossibleAssignment of the replica is empty, indicating this is
a new replica.
+ // Then the baseline is the only reference.
+ return calculateAssignmentScore(nodeName, state, baselineAssignment);
+ } else {
+ // Else, for minimizing partition movements or state transitions,
prioritize the proposed
+ // assignment that matches the previous Best Possible assignment.
+ double score = calculateAssignmentScore(nodeName, state,
bestPossibleAssignment);
+ // If no Best Possible assignment matches, check the baseline assignment.
+ if (score == 0 && baselineAssignment.containsKey(nodeName)) {
Review comment:
If I understand it correctly, when score == 0, should this be same as
bestpossible is Empty()? Then score should be
calculateAssignmentScore(nodeName, state, baselineAssignment);
----------------------------------------------------------------
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]