|
19 | 19 | * under the License. |
20 | 20 | */ |
21 | 21 |
|
22 | | -import org.apache.helix.HelixException; |
23 | 22 | import org.apache.helix.HelixManager; |
| 23 | +import org.apache.helix.HelixRebalanceException; |
| 24 | +import org.apache.helix.controller.changedetector.ResourceChangeDetector; |
24 | 25 | import org.apache.helix.controller.dataproviders.ResourceControllerDataProvider; |
25 | | -import org.apache.helix.controller.rebalancer.GlobalRebalancer; |
| 26 | +import org.apache.helix.controller.rebalancer.DelayedAutoRebalancer; |
| 27 | +import org.apache.helix.controller.rebalancer.internal.MappingCalculator; |
| 28 | +import org.apache.helix.controller.rebalancer.waged.constraints.ConstraintsRebalanceAlgorithm; |
26 | 29 | import org.apache.helix.controller.stages.CurrentStateOutput; |
27 | 30 | import org.apache.helix.model.IdealState; |
28 | 31 | import org.apache.helix.model.Resource; |
|
36 | 39 | * A placeholder before we have the implementation. |
37 | 40 | * Weight-Aware Globally-Even Distribute Rebalancer. |
38 | 41 | * |
39 | | - * @see <a href="Design Document">https://github.com/apache/helix/wiki/Design-Proposal---Weight-Aware-Globally-Even-Distribute-Rebalancer</a> |
| 42 | + * @see <a href="https://github.com/apache/helix/wiki/Design-Proposal---Weight-Aware-Globally-Even-Distribute-Rebalancer"> |
| 43 | + * Design Document |
| 44 | + * </a> |
40 | 45 | */ |
41 | | -public class WagedRebalancer implements GlobalRebalancer<ResourceControllerDataProvider> { |
| 46 | +public class WagedRebalancer { |
42 | 47 | private static final Logger LOG = LoggerFactory.getLogger(WagedRebalancer.class); |
43 | 48 |
|
44 | | - @Override |
45 | | - public void init(HelixManager manager) { } |
| 49 | + // --------- The following fields are placeholders and need replacement. -----------// |
| 50 | + // TODO Shall we make the metadata store a static threadlocal object as well to avoid reinitialization? |
| 51 | + private final AssignmentMetadataStore _assignmentMetadataStore; |
| 52 | + private final RebalanceAlgorithm _rebalanceAlgorithm; |
| 53 | + // ------------------------------------------------------------------------------------// |
46 | 54 |
|
47 | | - @Override |
48 | | - public Map<String, IdealState> computeNewIdealState(CurrentStateOutput currentStateOutput, |
49 | | - ResourceControllerDataProvider clusterData, Map<String, Resource> resourceMap) |
50 | | - throws HelixException { |
51 | | - return new HashMap<>(); |
| 55 | + // The cluster change detector is a stateful object. Make it static to avoid unnecessary |
| 56 | + // reinitialization. |
| 57 | + private static final ThreadLocal<ResourceChangeDetector> CHANGE_DETECTOR_THREAD_LOCAL = |
| 58 | + new ThreadLocal<>(); |
| 59 | + private final MappingCalculator<ResourceControllerDataProvider> _mappingCalculator; |
| 60 | + |
| 61 | + private ResourceChangeDetector getChangeDetector() { |
| 62 | + if (CHANGE_DETECTOR_THREAD_LOCAL.get() == null) { |
| 63 | + CHANGE_DETECTOR_THREAD_LOCAL.set(new ResourceChangeDetector()); |
| 64 | + } |
| 65 | + return CHANGE_DETECTOR_THREAD_LOCAL.get(); |
| 66 | + } |
| 67 | + |
| 68 | + public WagedRebalancer(HelixManager helixManager) { |
| 69 | + // TODO init the metadata store according to their requirement when integrate, or change to final static method if possible. |
| 70 | + _assignmentMetadataStore = new AssignmentMetadataStore(); |
| 71 | + // TODO init the algorithm according to the requirement when integrate. |
| 72 | + _rebalanceAlgorithm = new ConstraintsRebalanceAlgorithm(); |
| 73 | + |
| 74 | + // Use the mapping calculator in DelayedAutoRebalancer for calculating the final assignment |
| 75 | + // output. |
| 76 | + // This calculator will translate the best possible assignment into an applicable state mapping |
| 77 | + // based on the current states. |
| 78 | + // TODO abstract and separate the mapping calculator logic from the DelayedAutoRebalancer |
| 79 | + _mappingCalculator = new DelayedAutoRebalancer(); |
52 | 80 | } |
53 | 81 |
|
54 | | - @Override |
55 | | - public RebalanceFailureReason getFailureReason() { |
56 | | - return new RebalanceFailureReason(RebalanceFailureType.UNKNOWN_FAILURE); |
| 82 | + /** |
| 83 | + * Compute the new IdealStates for all the resources input. The IdealStates include both the new |
| 84 | + * partition assignment (in the listFiles) and the new replica state mapping (in the mapFields). |
| 85 | + * @param clusterData The Cluster status data provider. |
| 86 | + * @param resourceMap A map containing all the rebalancing resources. |
| 87 | + * @param currentStateOutput The present Current State of the cluster. |
| 88 | + * @return A map containing the computed new IdealStates. |
| 89 | + */ |
| 90 | + public Map<String, IdealState> computeNewIdealStates(ResourceControllerDataProvider clusterData, |
| 91 | + Map<String, Resource> resourceMap, final CurrentStateOutput currentStateOutput) |
| 92 | + throws HelixRebalanceException { |
| 93 | + return new HashMap<>(); |
57 | 94 | } |
58 | 95 | } |
0 commit comments