Skip to content

Commit

Permalink
Pass the preference keys instead of cluster config
Browse files Browse the repository at this point in the history
  • Loading branch information
ywang4 committed Sep 17, 2019
1 parent a786db4 commit 3bf4feb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ public class WagedRebalancer {
private final RebalanceAlgorithm _rebalanceAlgorithm;
// ------------------------------------------------------------------------------------//

public WagedRebalancer(HelixManager helixManager, ClusterConfig clusterConfig) {
public WagedRebalancer(HelixManager helixManager,
Map<ClusterConfig.GlobalRebalancePreferenceKey, Integer> preferences) {
this(
// TODO init the metadata store according to their requirement when integrate,
// or change to final static method if possible.
new AssignmentMetadataStore(helixManager),
ConstraintBasedAlgorithmFactory.getInstance(clusterConfig),
new AssignmentMetadataStore(helixManager), ConstraintBasedAlgorithmFactory.getInstance(preferences),
// Use DelayedAutoRebalancer as the mapping calculator for the final assignment output.
// Mapping calculator will translate the best possible assignment into the applicable state
// mapping based on the current states.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,31 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;


/**
* The factory class to create an instance of {@link ConstraintBasedAlgorithm}
*/
public class ConstraintBasedAlgorithmFactory {

public static RebalanceAlgorithm getInstance(ClusterConfig clusterConfig) {
public static RebalanceAlgorithm getInstance(Map<ClusterConfig.GlobalRebalancePreferenceKey, Integer> preferences) {
List<HardConstraint> hardConstraints =
ImmutableList.of(new FaultZoneAwareConstraint(), new NodeCapacityConstraint(),
new ReplicaActivateConstraint(), new NodeMaxPartitionLimitConstraint(),
new ValidGroupTagConstraint(), new SamePartitionOnInstanceConstraint());

int evennessPreference = clusterConfig.getGlobalRebalancePreference()
.get(ClusterConfig.GlobalRebalancePreferenceKey.EVENNESS);
int movementPreference = clusterConfig.getGlobalRebalancePreference()
.get(ClusterConfig.GlobalRebalancePreferenceKey.LESS_MOVEMENT);
ImmutableList.of(new FaultZoneAwareConstraint(), new NodeCapacityConstraint(), new ReplicaActivateConstraint(),
new NodeMaxPartitionLimitConstraint(), new ValidGroupTagConstraint(),
new SamePartitionOnInstanceConstraint());

int evennessPreference = preferences.getOrDefault(ClusterConfig.GlobalRebalancePreferenceKey.EVENNESS, 1);
int movementPreference = preferences.getOrDefault(ClusterConfig.GlobalRebalancePreferenceKey.LESS_MOVEMENT, 1);
float evennessRatio = (float) evennessPreference / (evennessPreference + movementPreference);
float movementRatio = (float) movementPreference / (evennessPreference + movementPreference);

Map<SoftConstraint, Float> softConstraints = ImmutableMap.<SoftConstraint, Float> builder()
Map<SoftConstraint, Float> softConstraints = ImmutableMap.<SoftConstraint, Float>builder()
// TODO: merge with PartitionMovementConstraint
// .put(new PartitionMovementConstraint(), movementRatio)
// .put(new PartitionMovementConstraint(), movementRatio * 0.5f)
.put(new InstancePartitionsCountConstraint(), 0.5f * evennessRatio)
.put(new ResourcePartitionAntiAffinityConstraint(), 0.1f * evennessRatio)
.put(new ResourceTopStateAntiAffinityConstraint(), 0.1f * evennessRatio)
.put(new MaxCapacityUsageInstanceConstraint(), 0.25f * evennessRatio).build();
.put(new MaxCapacityUsageInstanceConstraint(), 0.25f * evennessRatio)
.build();

return new ConstraintBasedAlgorithm(hardConstraints, softConstraints);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.helix.controller.rebalancer.SemiAutoRebalancer;
import org.apache.helix.controller.rebalancer.internal.MappingCalculator;
import org.apache.helix.controller.rebalancer.waged.WagedRebalancer;
import org.apache.helix.model.ClusterConfig;
import org.apache.helix.model.IdealState;
import org.apache.helix.model.InstanceConfig;
import org.apache.helix.model.MaintenanceSignal;
Expand Down Expand Up @@ -121,7 +122,9 @@ private BestPossibleStateOutput compute(ClusterEvent event, Map<String, Resource
// configured to use the WAGED rebalancer.
// For the other resources, the legacy rebalancers will be triggered in the next step.
Map<String, IdealState> newIdealStates = new HashMap<>();
WagedRebalancer wagedRebalancer = new WagedRebalancer(helixManager, cache.getClusterConfig());
Map<ClusterConfig.GlobalRebalancePreferenceKey, Integer> preferences = cache.getClusterConfig()
.getGlobalRebalancePreference();
WagedRebalancer wagedRebalancer = new WagedRebalancer(helixManager, preferences);
try {
newIdealStates
.putAll(wagedRebalancer.computeNewIdealStates(cache, resourceMap, currentStateOutput));
Expand Down

0 comments on commit 3bf4feb

Please sign in to comment.