You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@helix.apache.org by GitBox <gi...@apache.org> on 2021/05/14 01:34:47 UTC
[GitHub] [helix] jiajunwang commented on a change in pull request #1724: Applying per replica logic for entire stage
jiajunwang commented on a change in pull request #1724:
URL: https://github.com/apache/helix/pull/1724#discussion_r632147749
##########
File path: helix-core/src/main/java/org/apache/helix/controller/common/PartitionStateMap.java
##########
@@ -39,10 +39,18 @@ public PartitionStateMap(String resourceName) {
_stateMap = new HashMap<>();
}
+ // Deep copy of the partitionStateMap is a safer way.
public PartitionStateMap(String resourceName,
Map<Partition, Map<String, String>> partitionStateMap) {
_resourceName = resourceName;
- _stateMap = partitionStateMap;
+ _stateMap = new HashMap<>();
+ for (Partition partition : partitionStateMap.keySet()) {
+ Map<String, String> map = new HashMap<>();
+ for (Map.Entry<String, String> entry : partitionStateMap.get(partition).entrySet()) {
+ map.put(entry.getKey(), entry.getValue());
+ }
+ _stateMap.put(partition, map);
Review comment:
nit, _stateMap.put(partition, new HashMap<>(partitionStateMap.get(partition))); ?
And stream() should help to make it even simpler.
##########
File path: helix-core/src/main/java/org/apache/helix/controller/stages/IntermediateStateCalcStage.java
##########
@@ -294,99 +294,43 @@ private PartitionStateMap computeIntermediatePartitionState(ResourceControllerDa
ClusterStatusMonitor clusterStatusMonitor, IdealState idealState, Resource resource,
CurrentStateOutput currentStateOutput, PartitionStateMap bestPossiblePartitionStateMap,
Map<String, List<String>> preferenceLists,
- StateTransitionThrottleController throttleController) {
+ StateTransitionThrottleController throttleController, Map<Partition, List<Message>> resourceMessageMap) {
String resourceName = resource.getResourceName();
LogUtil.logDebug(logger, _eventId, String.format("Processing resource: %s", resourceName));
- // Throttling is applied only on FULL-AUTO mode
- if (!throttleController.isThrottleEnabled()
- || !IdealState.RebalanceMode.FULL_AUTO.equals(idealState.getRebalanceMode())) {
+ // Throttling is applied only on FULL-AUTO mode and if the resource message map is empty, no throttling needed.
+ if (!throttleController.isThrottleEnabled() || !IdealState.RebalanceMode.FULL_AUTO.equals(
+ idealState.getRebalanceMode()) || resourceMessageMap.isEmpty()) {
return bestPossiblePartitionStateMap;
}
String stateModelDefName = idealState.getStateModelDefRef();
StateModelDefinition stateModelDef = cache.getStateModelDef(stateModelDefName);
- PartitionStateMap intermediatePartitionStateMap = new PartitionStateMap(resourceName);
+ // This require a deep copy of current state map because some of the states will be overwritten by applying
+ // messages to it.
+ PartitionStateMap intermediatePartitionStateMap =
Review comment:
I guess you will need to apply the selected messages one by one to update this map. Is it possible we do this calculation in an async thread or whenever it is really used? It would be slow, and I remember the consumers are all for monitoring or optional update.
##########
File path: helix-core/src/main/java/org/apache/helix/controller/stages/IntermediateStateCalcStage.java
##########
@@ -396,23 +340,74 @@ private PartitionStateMap computeIntermediatePartitionState(ResourceControllerDa
// Perform regular load balance only if the number of partitions in recovery and in error is
// less than the threshold. Otherwise, only allow downward-transition load balance
- boolean onlyDownwardLoadBalance = partitionCount > threshold;
+ boolean onlyDownwardLoadBalance = numPartitionsWithErrorReplica > threshold;
+
+ chargePendingTransition(resource, currentStateOutput, throttleController, cache, preferenceLists, stateModelDef,
+ intermediatePartitionStateMap);
+
+ // Sort partitions in case of urgent partition need to take the quota first.
+ List<Partition> partitions = new ArrayList<>(resource.getPartitions());
+ Collections.sort(partitions, new PartitionPriorityComparator(bestPossiblePartitionStateMap.getStateMap(),
+ currentStateOutput.getCurrentStateMap(resourceName), stateModelDef.getTopState()));
+ for (Partition partition : partitions) {
+ Map<String, String> derivedCurrentStateMap = currentStateOutput.getCurrentStateMap(resourceName, partition)
+ .entrySet()
+ .stream()
+ .collect(Collectors.toMap(entry -> entry.getKey(), entry -> entry.getValue()));
+ List<String> preferenceList = preferenceLists.get(partition.getPartitionName());
+ Map<String, Integer> requiredState = getRequiredStates(resourceName, cache, preferenceList);
+ List<Message> messagesToThrottle = new ArrayList<>(resourceMessageMap.get(partition));
+ if (messagesToThrottle == null || messagesToThrottle.isEmpty()) {
Review comment:
nit move to the beginning to avoid unnecessary current state converting?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org