Persist preference list improve
Project: http://git-wip-us.apache.org/repos/asf/helix/repo Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/1c855ae8 Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/1c855ae8 Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/1c855ae8 Branch: refs/heads/master Commit: 1c855ae8506d67e0826c8385fb04bb990f0e8f95 Parents: 8efb359 Author: Junkai Xue <[email protected]> Authored: Mon Sep 25 15:22:30 2017 -0700 Committer: Junkai Xue <[email protected]> Committed: Mon Sep 25 16:39:51 2017 -0700 ---------------------------------------------------------------------- .../stages/BestPossibleStateCalcStage.java | 1 + .../stages/BestPossibleStateOutput.java | 42 ++++++++++++++++++++ .../helix/task/TestSemiAutoStateTransition.java | 3 +- 3 files changed, 45 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/helix/blob/1c855ae8/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 f2e9da7..fbb7f86 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 @@ -155,6 +155,7 @@ public class BestPossibleStateCalcStage extends AbstractBaseStage { HelixManager manager = event.getAttribute("helixmanager"); rebalancer.init(manager); idealState = rebalancer.computeNewIdealState(resourceName, idealState, currentStateOutput, cache); + output.setPreferenceLists(resourceName, idealState.getPreferenceLists()); // Use the internal MappingCalculator interface to compute the final assignment // The next release will support rebalancers that compute the mapping from start to finish http://git-wip-us.apache.org/repos/asf/helix/blob/1c855ae8/helix-core/src/main/java/org/apache/helix/controller/stages/BestPossibleStateOutput.java ---------------------------------------------------------------------- diff --git a/helix-core/src/main/java/org/apache/helix/controller/stages/BestPossibleStateOutput.java b/helix-core/src/main/java/org/apache/helix/controller/stages/BestPossibleStateOutput.java index 947e4d0..c64c8cf 100644 --- a/helix-core/src/main/java/org/apache/helix/controller/stages/BestPossibleStateOutput.java +++ b/helix-core/src/main/java/org/apache/helix/controller/stages/BestPossibleStateOutput.java @@ -21,6 +21,7 @@ package org.apache.helix.controller.stages; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.apache.helix.controller.common.PartitionStateMap; import org.apache.helix.controller.common.ResourcesStateMap; @@ -30,6 +31,8 @@ import org.apache.helix.model.Partition; * Output for BestPossibleStateCalStage. */ public class BestPossibleStateOutput extends ResourcesStateMap { + /* resource -> partition -> preference list */ + private Map<String, Map<String, List<String>>> _preferenceLists; /** * Deprecated, use getResourceStatesMap instead. * @@ -59,4 +62,43 @@ public class BestPossibleStateOutput extends ResourcesStateMap { } return stateMap; } + + public Map<String, Map<String, List<String>>> getPreferenceLists() { + return _preferenceLists; + } + + public Map<String, List<String>> getPreferenceLists(String resource) { + if (_preferenceLists != null && _preferenceLists.containsKey(resource)) { + return _preferenceLists.get(resource); + } + + return null; + } + + public List<String> getPreferenceList(String resource, String partition) { + if (_preferenceLists != null && _preferenceLists.containsKey(resource) && _preferenceLists + .get(resource).containsKey(partition)) { + return _preferenceLists.get(resource).get(partition); + } + + return null; + } + + public void setPreferenceList(String resource, String partition, List<String> list) { + if (_preferenceLists == null) { + _preferenceLists = new HashMap<String, Map<String, List<String>>>(); + } + if (!_preferenceLists.containsKey(resource)) { + _preferenceLists.put(resource, new HashMap<String, List<String>>()); + } + _preferenceLists.get(resource).put(partition, list); + } + + public void setPreferenceLists(String resource, + Map<String, List<String>> resourcePreferenceLists) { + if (_preferenceLists == null) { + _preferenceLists = new HashMap<String, Map<String, List<String>>>(); + } + _preferenceLists.put(resource, resourcePreferenceLists); + } } http://git-wip-us.apache.org/repos/asf/helix/blob/1c855ae8/helix-core/src/test/java/org/apache/helix/task/TestSemiAutoStateTransition.java ---------------------------------------------------------------------- diff --git a/helix-core/src/test/java/org/apache/helix/task/TestSemiAutoStateTransition.java b/helix-core/src/test/java/org/apache/helix/task/TestSemiAutoStateTransition.java index 4a62cca..6de2f10 100644 --- a/helix-core/src/test/java/org/apache/helix/task/TestSemiAutoStateTransition.java +++ b/helix-core/src/test/java/org/apache/helix/task/TestSemiAutoStateTransition.java @@ -45,6 +45,7 @@ public class TestSemiAutoStateTransition extends TaskTestBase { @BeforeClass public void beforeClass() throws Exception { _numParitions = 1; + _participants = new MockParticipantManager[_numNodes]; String namespace = "/" + CLUSTER_NAME; if (_gZkClient.exists(namespace)) { @@ -105,4 +106,4 @@ public class TestSemiAutoStateTransition extends TaskTestBase { Assert.assertEquals("MASTER", stateMap.get(PARTICIPANT_PREFIX + "_" + (_startPort + 1))); Assert.assertEquals("SLAVE", stateMap.get(PARTICIPANT_PREFIX + "_" + (_startPort + 2))); } -} +} \ No newline at end of file
