From dfb5d01a414426ca3700c03491a68841b9ba8c83 Mon Sep 17 00:00:00 2001 From: jiajunwang Date: Fri, 9 Aug 2019 15:22:51 -0700 Subject: [PATCH] Change the rebalancer assignment record to be ResourceAssignment instead of IdealState. ResourceAssignment fit the usage better. And there will be no unnecessary information to be recorded or read during the rebalance calculation. --- .../rebalancer/waged/RebalanceAlgorithm.java | 3 ++- .../ConstraintsRebalanceAlgorithm.java | 3 ++- .../rebalancer/waged/model/ClusterModel.java | 17 +++++++++-------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/RebalanceAlgorithm.java b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/RebalanceAlgorithm.java index 0e6c89122c..ae258ca637 100644 --- a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/RebalanceAlgorithm.java +++ b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/RebalanceAlgorithm.java @@ -22,6 +22,7 @@ import org.apache.helix.controller.rebalancer.waged.constraints.HardConstraint; import org.apache.helix.controller.rebalancer.waged.model.ClusterModel; import org.apache.helix.model.IdealState; +import org.apache.helix.model.ResourceAssignment; import java.util.Map; @@ -40,6 +41,6 @@ public interface RebalanceAlgorithm { * If the map is null, no failure will be returned. * @return A map of the rebalanced resource assignments that are saved in the IdeaStates. */ - Map rebalance(ClusterModel clusterModel, + Map rebalance(ClusterModel clusterModel, Map> failureReasons); } diff --git a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/constraints/ConstraintsRebalanceAlgorithm.java b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/constraints/ConstraintsRebalanceAlgorithm.java index 292d90383f..a75854a4cc 100644 --- a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/constraints/ConstraintsRebalanceAlgorithm.java +++ b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/constraints/ConstraintsRebalanceAlgorithm.java @@ -22,6 +22,7 @@ import org.apache.helix.controller.rebalancer.waged.RebalanceAlgorithm; import org.apache.helix.controller.rebalancer.waged.model.ClusterModel; import org.apache.helix.model.IdealState; +import org.apache.helix.model.ResourceAssignment; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,7 +43,7 @@ public ConstraintsRebalanceAlgorithm() { } @Override - public Map rebalance(ClusterModel clusterModel, + public Map rebalance(ClusterModel clusterModel, Map> failureReasons) { return new HashMap<>(); } diff --git a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/model/ClusterModel.java b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/model/ClusterModel.java index 2908939032..1be527a80f 100644 --- a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/model/ClusterModel.java +++ b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/model/ClusterModel.java @@ -21,6 +21,7 @@ import org.apache.helix.HelixException; import org.apache.helix.model.IdealState; +import org.apache.helix.model.ResourceAssignment; import java.util.Collections; import java.util.Map; @@ -40,10 +41,10 @@ public class ClusterModel { private final Map _assignableNodeMap; // Records about the previous assignment - // - private final Map _baselineAssignment; - // - private final Map _bestPossibleAssignment; + // + private final Map _baselineAssignment; + // + private final Map _bestPossibleAssignment; /** * @param clusterContext The initialized cluster context. @@ -54,8 +55,8 @@ public class ClusterModel { * @param bestPossibleAssignment The current best possible assignment. */ ClusterModel(ClusterContext clusterContext, Set assignableReplicas, - Set assignableNodes, Map baselineAssignment, - Map bestPossibleAssignment) { + Set assignableNodes, Map baselineAssignment, + Map bestPossibleAssignment) { _clusterContext = clusterContext; // Save all the to be assigned replication @@ -87,11 +88,11 @@ public Map> getAssignableReplicaMap() { return _assignableReplicaMap; } - public Map getBaseline() { + public Map getBaseline() { return _baselineAssignment; } - public Map getBestPossibleAssignment() { + public Map getBestPossibleAssignment() { return _bestPossibleAssignment; }