Github user lei-xia commented on a diff in the pull request:
https://github.com/apache/helix/pull/59#discussion_r88552181
--- Diff:
helix-core/src/main/java/org/apache/helix/controller/rebalancer/strategy/AutoRebalanceStrategy.java
---
@@ -791,43 +795,61 @@ public String getLocation(int partitionId, int
replicaId, int numPartitions, int
}
/**
- * Sorter for live nodes that sorts firstly according to the number of
partitions currently
- * registered against a node (more partitions means sort earlier), then
by node name.
+ * Sorter for live nodes that sorts
+ * - first by the sum of "state scores" of partitions currently
registered to a node
+ * (more higher-priority partitions means sort earlier)
+ * - then by node name.
* This prevents unnecessarily moving partitions due to the capacity
assignment
* unnecessarily reducing the capacity of lower down elements.
*/
private static class CurrentStateNodeComparator implements
Comparator<String> {
/**
- * The number of partitions that are active for each participant.
+ * The sum of state scores for partitions on each .
(Map<ParticipantId, Integer>)
+ * State scores are the reverse of state priorities, s.t. states with
lower priority numbers have higher scores.
*/
- private final Map<String, Integer> partitionCounts;
+ private final Map<String, Integer> participantStatePriorities;
/**
* Create it.
* @param currentMapping The current mapping of partitions to
participants.
+ * @param stateModelDef The resource's associated state model.
*/
- public CurrentStateNodeComparator(Map<String, Map<String, String>>
currentMapping) {
- partitionCounts = new HashMap<String, Integer>();
- for (Entry<String, Map<String, String>> entry :
currentMapping.entrySet()) {
- for (String participantId : entry.getValue().keySet()) {
- Integer existing = partitionCounts.get(participantId);
- partitionCounts.put(participantId, existing != null ? existing +
1 : 1);
+ public CurrentStateNodeComparator(Map<String, Map<String, String>>
currentMapping,
+ StateModelDefinition stateModelDef) {
+ Map<String, Integer> stateScores = getStateScores(stateModelDef);
+
+ participantStatePriorities = new HashMap<String, Integer>();
+ for (Map<String, String> participantStates :
currentMapping.values()) {
+ for (String participantId : participantStates.keySet()) {
+ int existing =
participantStatePriorities.getOrDefault(participantId, 0);
--- End diff --
Also, you are using Java 8 feature, Helix still use Java 6 now, please
refactor this.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---