This is an automated email from the ASF dual-hosted git repository.
xyuanlu 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 5de9232d9 Improve performance for ConstraintBasedAlgorithm(#3032)
5de9232d9 is described below
commit 5de9232d98f0aa4391eebfce51ca61ef72cc1c2e
Author: xyuanlu <[email protected]>
AuthorDate: Tue May 6 17:34:30 2025 -0700
Improve performance for ConstraintBasedAlgorithm(#3032)
Improve performance for ConstraintBasedAlgorithm
---
.../waged/constraints/ConstraintBasedAlgorithm.java | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git
a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/constraints/ConstraintBasedAlgorithm.java
b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/constraints/ConstraintBasedAlgorithm.java
index c40ad8848..fb3951a6e 100644
---
a/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/constraints/ConstraintBasedAlgorithm.java
+++
b/helix-core/src/main/java/org/apache/helix/controller/rebalancer/waged/constraints/ConstraintBasedAlgorithm.java
@@ -118,18 +118,19 @@ class ConstraintBasedAlgorithm implements
RebalanceAlgorithm {
}
private Optional<AssignableNode> getNodeWithHighestPoints(AssignableReplica
replica,
- List<AssignableNode> assignableNodes, ClusterContext clusterContext,
- Set<String> busyInstances, OptimalAssignment optimalAssignment) {
- Map<AssignableNode, List<HardConstraint>> hardConstraintFailures = new
ConcurrentHashMap<>();
+ List<AssignableNode> assignableNodes, ClusterContext clusterContext,
Set<String> busyInstances,
+ OptimalAssignment optimalAssignment) {
+ Map<AssignableNode, List<HardConstraint>> hardConstraintFailures = new
ConcurrentHashMap<>(assignableNodes.size());
List<AssignableNode> candidateNodes =
assignableNodes.parallelStream().filter(candidateNode -> {
boolean isValid = true;
- // need to record all the failure reasons and it gives us the ability to
debug/fix the runtime
- // cluster environment
for (HardConstraint hardConstraint : _hardConstraints) {
if (!hardConstraint.isAssignmentValid(candidateNode, replica,
clusterContext)) {
- hardConstraintFailures.computeIfAbsent(candidateNode, node -> new
ArrayList<>())
- .add(hardConstraint);
+ if (!hardConstraintFailures.containsKey(candidateNode)) {
+ hardConstraintFailures.put(candidateNode, new ArrayList<>());
+ }
+ hardConstraintFailures.get(candidateNode).add(hardConstraint);
isValid = false;
+ break;
}
}
return isValid;