forked from apache/helix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redefine the hard/soft constraints (apache#422)
* Refactor the interfaces of hard/soft constraints and a central place to keep the softConstraint weights
- Loading branch information
1 parent
55e21b8
commit 672c9cb
Showing
6 changed files
with
159 additions
and
119 deletions.
There are no files selected for viewing
45 changes: 0 additions & 45 deletions
45
...x-core/src/main/java/org/apache/helix/controller/rebalancer/waged/RebalanceAlgorithm.java
This file was deleted.
Oops, something went wrong.
49 changes: 0 additions & 49 deletions
49
...g/apache/helix/controller/rebalancer/waged/constraints/ConstraintsRebalanceAlgorithm.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...g/apache/helix/controller/rebalancer/waged/constraints/LeastPartitionCountConstraint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.apache.helix.controller.rebalancer.waged.constraints; | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import org.apache.helix.controller.rebalancer.waged.model.AssignableNode; | ||
import org.apache.helix.controller.rebalancer.waged.model.AssignableReplica; | ||
import org.apache.helix.controller.rebalancer.waged.model.ClusterContext; | ||
|
||
/** | ||
* Evaluate the proposed assignment according to the instance's partition count. | ||
*/ | ||
class LeastPartitionCountConstraint extends SoftConstraint { | ||
static LeastPartitionCountConstraint INSTANCE = new LeastPartitionCountConstraint(); | ||
|
||
private LeastPartitionCountConstraint() { | ||
} | ||
|
||
/** | ||
* Returns a score depending on the number of assignments on this node. The score is scaled evenly | ||
* between the minScore and maxScore. | ||
* When the node is idle, return with the maxScore. | ||
* When the node usage reaches the estimated max partition, return with (minScore + maxScore ) / | ||
* 2. | ||
* When the node usage reaches 2 * estimated_max or more, return with the minScore. | ||
* If the estimated max partition count is not set, it defaults to Integer.MAX_VALUE in | ||
* clusterContext. | ||
*/ | ||
@Override | ||
float getAssignmentOriginScore(AssignableNode node, AssignableReplica replica, | ||
ClusterContext clusterContext) { | ||
throw new UnsupportedOperationException("The POC implementation has a bug, will fix it as TODO"); | ||
// float doubleMaxPartitionCount = 2.0f * clusterContext.getEstimatedMaxPartitionCount(); | ||
// int curPartitionCount = node.getCurrentAssignmentCount(); | ||
// return Math.max((doubleMaxPartitionCount - curPartitionCount) / doubleMaxPartitionCount, 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...a/org/apache/helix/controller/rebalancer/waged/constraints/SoftConstraintWeightModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.apache.helix.controller.rebalancer.waged.constraints; | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import java.util.Map; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
|
||
/** | ||
* The class retrieves the offline model that defines the relative importance of soft constraints. | ||
*/ | ||
class SoftConstraintWeightModel { | ||
private static Map<? extends SoftConstraint, Float> MODEL; | ||
|
||
static { | ||
// TODO either define the weights in property files or zookeeper node or static human input | ||
MODEL = ImmutableMap.<SoftConstraint, Float> builder() | ||
.put(LeastPartitionCountConstraint.INSTANCE, 1.0f).build(); | ||
} | ||
|
||
/** | ||
* Get the sum of normalized scores, given calculated scores map of soft constraints | ||
* @param originScoresMap The origin scores by soft constraints | ||
* @return The sum of soft constraints scores | ||
*/ | ||
float getSumOfScores(Map<SoftConstraint, Float> originScoresMap) { | ||
float sum = 0; | ||
for (Map.Entry<SoftConstraint, Float> softConstraintScoreEntry : originScoresMap.entrySet()) { | ||
SoftConstraint softConstraint = softConstraintScoreEntry.getKey(); | ||
float score = softConstraint.getScalerFunction().scale(softConstraintScoreEntry.getValue()); | ||
float weight = MODEL.get(softConstraint); | ||
sum += score * weight; | ||
} | ||
|
||
return sum; | ||
} | ||
} |