You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by ji...@apache.org on 2019/10/28 22:32:42 UTC

[helix] 04/50: Change the rebalancer assignment record to be ResourceAssignment instead of IdealState. (#398)

This is an automated email from the ASF dual-hosted git repository.

jiajunwang pushed a commit to branch wagedRebalancer
in repository https://gitbox.apache.org/repos/asf/helix.git

commit ba6436518d1277a60bc58007bb4e60adcfad8867
Author: Jiajun Wang <18...@users.noreply.github.com>
AuthorDate: Fri Aug 9 15:35:54 2019 -0700

    Change the rebalancer assignment record to be ResourceAssignment instead of IdealState. (#398)
    
    ResourceAssignment fit the usage better. And there will be no unnecessary information to be recorded or read during the rebalance calculation.
---
 .../controller/rebalancer/waged/RebalanceAlgorithm.java |  3 ++-
 .../constraints/ConstraintsRebalanceAlgorithm.java      |  3 ++-
 .../controller/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 0e6c891..ae258ca 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 @@ package org.apache.helix.controller.rebalancer.waged;
 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 <ResourceName, FailureReason> of the rebalanced resource assignments that are saved in the IdeaStates.
    */
-  Map<String, IdealState> rebalance(ClusterModel clusterModel,
+  Map<String, ResourceAssignment> rebalance(ClusterModel clusterModel,
       Map<String, Map<HardConstraint.FailureReason, Integer>> 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 292d903..a75854a 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 @@ package org.apache.helix.controller.rebalancer.waged.constraints;
 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 class ConstraintsRebalanceAlgorithm implements RebalanceAlgorithm {
   }
 
   @Override
-  public Map<String, IdealState> rebalance(ClusterModel clusterModel,
+  public Map<String, ResourceAssignment> rebalance(ClusterModel clusterModel,
       Map<String, Map<HardConstraint.FailureReason, Integer>> 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 2908939..1be527a 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 @@ package org.apache.helix.controller.rebalancer.waged.model;
 
 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<String, AssignableNode> _assignableNodeMap;
 
   // Records about the previous assignment
-  // <ResourceName, IdealState contains the baseline assignment>
-  private final Map<String, IdealState> _baselineAssignment;
-  // <ResourceName, IdealState contains the best possible assignment>
-  private final Map<String, IdealState> _bestPossibleAssignment;
+  // <ResourceName, ResourceAssignment contains the baseline assignment>
+  private final Map<String, ResourceAssignment> _baselineAssignment;
+  // <ResourceName, ResourceAssignment contains the best possible assignment>
+  private final Map<String, ResourceAssignment> _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<AssignableReplica> assignableReplicas,
-      Set<AssignableNode> assignableNodes, Map<String, IdealState> baselineAssignment,
-      Map<String, IdealState> bestPossibleAssignment) {
+      Set<AssignableNode> assignableNodes, Map<String, ResourceAssignment> baselineAssignment,
+      Map<String, ResourceAssignment> bestPossibleAssignment) {
     _clusterContext = clusterContext;
 
     // Save all the to be assigned replication
@@ -87,11 +88,11 @@ public class ClusterModel {
     return _assignableReplicaMap;
   }
 
-  public Map<String, IdealState> getBaseline() {
+  public Map<String, ResourceAssignment> getBaseline() {
     return _baselineAssignment;
   }
 
-  public Map<String, IdealState> getBestPossibleAssignment() {
+  public Map<String, ResourceAssignment> getBestPossibleAssignment() {
     return _bestPossibleAssignment;
   }