This is an automated email from the ASF dual-hosted git repository.
nealsun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git
The following commit(s) were added to refs/heads/master by this push:
new a31ce711a Fix minor unclean logics (#2254)
a31ce711a is described below
commit a31ce711afd7bd83d8d7b90f5ec9af777e4ad422
Author: Neal Sun <[email protected]>
AuthorDate: Thu Oct 27 11:32:35 2022 -0700
Fix minor unclean logics (#2254)
Fix minor unclean logics in rebalancer classes
---
.../helix/controller/rebalancer/DelayedAutoRebalancer.java | 5 ++---
.../helix/controller/rebalancer/waged/WagedRebalancer.java | 3 +--
.../helix/controller/stages/BestPossibleStateCalcStage.java | 10 ++++------
3 files changed, 7 insertions(+), 11 deletions(-)
diff --git
a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/DelayedAutoRebalancer.java
b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/DelayedAutoRebalancer.java
index 12004917f..bdb8ab63c 100644
---
a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/DelayedAutoRebalancer.java
+++
b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/DelayedAutoRebalancer.java
@@ -336,7 +336,7 @@ public class DelayedAutoRebalancer extends
AbstractRebalancer<ResourceController
&& numReplicas + numExtraReplicas - currentInstances.size() > 0) {
int subListSize = numReplicas + numExtraReplicas -
currentInstances.size();
combinedPreferenceList.addAll(instanceToAdd
- .subList(0, subListSize <= instanceToAdd.size() ? subListSize :
instanceToAdd.size()));
+ .subList(0, Math.min(subListSize, instanceToAdd.size())));
}
// Make all initial state instance not in preference list to be dropped.
@@ -344,8 +344,7 @@ public class DelayedAutoRebalancer extends
AbstractRebalancer<ResourceController
currentMapWithPreferenceList.keySet().retainAll(preferenceList);
combinedPreferenceList.addAll(currentInstances);
- Collections.sort(combinedPreferenceList,
- new PreferenceListNodeComparator(currentStateMap, stateModelDef,
preferenceList));
+ combinedPreferenceList.sort(new
PreferenceListNodeComparator(currentStateMap, stateModelDef, preferenceList));
// Assign states to instances with the combined preference list.
Map<String, String> bestPossibleStateMap =
diff --git
a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/WagedRebalancer.java
b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/WagedRebalancer.java
index 7221b1e0a..a99ad26ab 100644
---
a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/WagedRebalancer.java
+++
b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/WagedRebalancer.java
@@ -344,8 +344,7 @@ public class WagedRebalancer implements
StatefulRebalancer<ResourceControllerDat
// Note the user-defined list is intentionally applied to the final
mapping after calculation.
// This is to avoid persisting it into the assignment store, which impacts
the long term
// assignment evenness and partition movements.
- newIdealStates.entrySet().stream().forEach(idealStateEntry ->
applyUserDefinedPreferenceList(
- clusterData.getResourceConfig(idealStateEntry.getKey()),
idealStateEntry.getValue()));
+ newIdealStates.forEach((key, value) ->
applyUserDefinedPreferenceList(clusterData.getResourceConfig(key), value));
return newIdealStates;
}
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 81b3aa226..8223d9a36 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
@@ -325,9 +325,7 @@ public class BestPossibleStateCalcStage extends
AbstractBaseStage {
"Skip rebalancing using the WAGED rebalancer since it is not
configured in the rebalance pipeline.");
}
- Iterator<Resource> itr = wagedRebalancedResourceMap.values().iterator();
- while (itr.hasNext()) {
- Resource resource = itr.next();
+ for (Resource resource : wagedRebalancedResourceMap.values()) {
IdealState is = newIdealStates.get(resource.getResourceName());
// Check if the WAGED rebalancer has calculated the result for this
resource or not.
if (is != null && checkBestPossibleStateCalculation(is)) {
@@ -335,8 +333,8 @@ public class BestPossibleStateCalcStage extends
AbstractBaseStage {
updateBestPossibleStateOutput(output, resource, is);
} else {
failureResources.add(resource.getResourceName());
- LogUtil.logWarn(logger, _eventId, String
- .format("The calculated best possible states for %s is empty or
invalid.",
+ LogUtil.logWarn(logger, _eventId,
+ String.format("The calculated best possible states for %s is empty
or invalid.",
resource.getResourceName()));
}
}
@@ -387,7 +385,7 @@ public class BestPossibleStateCalcStage extends
AbstractBaseStage {
MappingCalculator<ResourceControllerDataProvider> mappingCalculator =
getMappingCalculator(rebalancer, resourceName);
- if (rebalancer == null || mappingCalculator == null) {
+ if (rebalancer == null) {
LogUtil.logError(logger, _eventId, "Error computing assignment for
resource " + resourceName
+ ". no rebalancer found. rebalancer: " + rebalancer + "
mappingCalculator: "
+ mappingCalculator);