Updated Branches: refs/heads/master ac8bbf728 -> 509f44319
[HELIX-205] Have user-defined rebalancers use RebalanceMode.USER_DEFINED, rb=13611 Project: http://git-wip-us.apache.org/repos/asf/incubator-helix/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-helix/commit/509f4431 Tree: http://git-wip-us.apache.org/repos/asf/incubator-helix/tree/509f4431 Diff: http://git-wip-us.apache.org/repos/asf/incubator-helix/diff/509f4431 Branch: refs/heads/master Commit: 509f4431970fbfc1f7b3aa076105fe4e60ac8fcd Parents: ac8bbf7 Author: zzhang <[email protected]> Authored: Wed Aug 21 11:05:12 2013 -0700 Committer: zzhang <[email protected]> Committed: Wed Aug 21 11:05:12 2013 -0700 ---------------------------------------------------------------------- .../helix/controller/stages/BestPossibleStateCalcStage.java | 5 ++--- .../helix/controller/stages/RebalanceIdealStateStage.java | 6 +++--- .../main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java | 7 +++++-- .../src/main/java/org/apache/helix/model/IdealState.java | 7 +++++-- .../integration/TestCustomizedIdealStateRebalancer.java | 9 ++++++--- 5 files changed, 21 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/509f4431/helix-core/src/main/java/org/apache/helix/controller/stages/BestPossibleStateCalcStage.java ---------------------------------------------------------------------- diff --git a/helix-core/src/main/java/org/apache/helix/controller/stages/BestPossibleStateCalcStage.java b/helix-core/src/main/java/org/apache/helix/controller/stages/BestPossibleStateCalcStage.java index 79e957c..6c6fe08 100644 --- a/helix-core/src/main/java/org/apache/helix/controller/stages/BestPossibleStateCalcStage.java +++ b/helix-core/src/main/java/org/apache/helix/controller/stages/BestPossibleStateCalcStage.java @@ -30,7 +30,6 @@ import org.apache.helix.controller.rebalancer.SemiAutoRebalancer; import org.apache.helix.model.IdealState; import org.apache.helix.model.Partition; import org.apache.helix.model.Resource; -import org.apache.helix.model.IdealState.IdealStateProperty; import org.apache.helix.model.IdealState.RebalanceMode; import org.apache.helix.util.HelixUtil; import org.apache.log4j.Logger; @@ -104,8 +103,8 @@ public class BestPossibleStateCalcStage extends AbstractBaseStage } Rebalancer rebalancer = null; - if(idealState.getRecord().getSimpleFields().containsKey( - IdealStateProperty.REBALANCER_CLASS_NAME.toString())) + if(idealState.getRebalanceMode() == RebalanceMode.USER_DEFINED + && idealState.getRebalancerClassName() != null) { String rebalancerClassName = idealState.getRebalancerClassName(); logger.info("resource " + resourceName + " use idealStateRebalancer " + rebalancerClassName); http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/509f4431/helix-core/src/main/java/org/apache/helix/controller/stages/RebalanceIdealStateStage.java ---------------------------------------------------------------------- diff --git a/helix-core/src/main/java/org/apache/helix/controller/stages/RebalanceIdealStateStage.java b/helix-core/src/main/java/org/apache/helix/controller/stages/RebalanceIdealStateStage.java index a049fef..b986d13 100644 --- a/helix-core/src/main/java/org/apache/helix/controller/stages/RebalanceIdealStateStage.java +++ b/helix-core/src/main/java/org/apache/helix/controller/stages/RebalanceIdealStateStage.java @@ -26,7 +26,7 @@ import org.apache.helix.HelixManager; import org.apache.helix.controller.pipeline.AbstractBaseStage; import org.apache.helix.controller.rebalancer.Rebalancer; import org.apache.helix.model.IdealState; -import org.apache.helix.model.IdealState.IdealStateProperty; +import org.apache.helix.model.IdealState.RebalanceMode; import org.apache.helix.util.HelixUtil; import org.apache.log4j.Logger; @@ -54,8 +54,8 @@ public class RebalanceIdealStateStage extends AbstractBaseStage for(String resourceName : idealStateMap.keySet()) { IdealState currentIdealState = idealStateMap.get(resourceName); - if(currentIdealState.getRecord().getSimpleFields().containsKey( - IdealStateProperty.REBALANCER_CLASS_NAME.toString())) + if(currentIdealState.getRebalanceMode() == RebalanceMode.USER_DEFINED + && currentIdealState.getRebalancerClassName() != null) { String rebalancerClassName = currentIdealState.getRebalancerClassName(); LOG.info("resource " + resourceName + " use idealStateRebalancer " + rebalancerClassName); http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/509f4431/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java ---------------------------------------------------------------------- diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java index a9226d3..7dfbe07 100644 --- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java +++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java @@ -276,6 +276,8 @@ public class ZKHelixAdmin implements HelixAdmin { if ((idealState.getRebalanceMode() == RebalanceMode.SEMI_AUTO && idealState.getPreferenceList(partitionName) == null) + || (idealState.getRebalanceMode() == RebalanceMode.USER_DEFINED + && idealState.getPreferenceList(partitionName) == null) || (idealState.getRebalanceMode() == RebalanceMode.CUSTOMIZED && idealState.getInstanceStateMap(partitionName) == null)) { @@ -1268,8 +1270,9 @@ public class ZKHelixAdmin implements HelixAdmin masterStateValue, slaveStateValue); - // for now keep mapField in AUTO mode and remove listField in CUSTOMIZED mode - if (idealState.getRebalanceMode() == RebalanceMode.SEMI_AUTO) + // for now keep mapField in SEMI_AUTO mode and remove listField in CUSTOMIZED mode + if (idealState.getRebalanceMode() == RebalanceMode.SEMI_AUTO + || idealState.getRebalanceMode() == RebalanceMode.USER_DEFINED) { idealState.getRecord().setListFields(newIdealState.getListFields()); idealState.getRecord().setMapFields(newIdealState.getMapFields()); http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/509f4431/helix-core/src/main/java/org/apache/helix/model/IdealState.java ---------------------------------------------------------------------- diff --git a/helix-core/src/main/java/org/apache/helix/model/IdealState.java b/helix-core/src/main/java/org/apache/helix/model/IdealState.java index 22e2328..48a3eee 100644 --- a/helix-core/src/main/java/org/apache/helix/model/IdealState.java +++ b/helix-core/src/main/java/org/apache/helix/model/IdealState.java @@ -135,6 +135,7 @@ public class IdealState extends HelixProperty if (property == RebalanceMode.NONE) { property = normalizeRebalanceMode(getIdealStateMode()); + setRebalanceMode(property); } return property; } @@ -175,7 +176,8 @@ public class IdealState extends HelixProperty public Set<String> getInstanceSet(String partitionName) { if (getRebalanceMode() == RebalanceMode.SEMI_AUTO - || getRebalanceMode() == RebalanceMode.FULL_AUTO) + || getRebalanceMode() == RebalanceMode.FULL_AUTO + || getRebalanceMode() == RebalanceMode.USER_DEFINED) { List<String> prefList = _record.getListField(partitionName); if (prefList != null) @@ -332,7 +334,8 @@ public class IdealState extends HelixProperty return false; } - if (getRebalanceMode() == RebalanceMode.SEMI_AUTO) + if (getRebalanceMode() == RebalanceMode.SEMI_AUTO + || getRebalanceMode() == RebalanceMode.USER_DEFINED) { String replicaStr = getReplicas(); if (replicaStr == null) { http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/509f4431/helix-core/src/test/java/org/apache/helix/integration/TestCustomizedIdealStateRebalancer.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestCustomizedIdealStateRebalancer.java b/helix-core/src/test/java/org/apache/helix/integration/TestCustomizedIdealStateRebalancer.java index 1d34e5b..291bfcf 100644 --- a/helix-core/src/test/java/org/apache/helix/integration/TestCustomizedIdealStateRebalancer.java +++ b/helix-core/src/test/java/org/apache/helix/integration/TestCustomizedIdealStateRebalancer.java @@ -25,7 +25,7 @@ import org.apache.helix.HelixDataAccessor; import org.apache.helix.HelixManager; import org.apache.helix.ZNRecord; import org.apache.helix.PropertyKey.Builder; -import org.apache.helix.controller.rebalancer.CustomRebalancer; +import org.apache.helix.controller.rebalancer.SemiAutoRebalancer; import org.apache.helix.controller.stages.ClusterDataCache; import org.apache.helix.controller.stages.CurrentStateOutput; import org.apache.helix.manager.zk.ZKHelixDataAccessor; @@ -45,7 +45,7 @@ public class TestCustomizedIdealStateRebalancer extends ZkStandAloneCMTestBaseWi String db2 = TEST_DB+"2"; static boolean testRebalancerCreated = false; - public static class TestRebalancer extends CustomRebalancer + public static class TestRebalancer extends SemiAutoRebalancer { @Override @@ -77,8 +77,11 @@ public class TestCustomizedIdealStateRebalancer extends ZkStandAloneCMTestBaseWi public void testCustomizedIdealStateRebalancer() throws InterruptedException { _setupTool.addResourceToCluster(CLUSTER_NAME, db2, 60, "MasterSlave"); - _setupTool.addResourceProperty(CLUSTER_NAME, db2, IdealStateProperty.REBALANCER_CLASS_NAME.toString(), + _setupTool.addResourceProperty(CLUSTER_NAME, db2, + IdealStateProperty.REBALANCER_CLASS_NAME.toString(), TestCustomizedIdealStateRebalancer.TestRebalancer.class.getName()); + _setupTool.addResourceProperty(CLUSTER_NAME, db2, IdealStateProperty.REBALANCE_MODE.toString(), + RebalanceMode.USER_DEFINED.toString()); _setupTool.rebalanceStorageCluster(CLUSTER_NAME, db2, 3);
