Skip to content

Commit

Permalink
Fixed primary shard balance constraints getting unset
Browse files Browse the repository at this point in the history
Signed-off-by: Smit Patel <patelsmit32123@gmail.com>
  • Loading branch information
patelsmit32123 committed Jan 22, 2025
1 parent 2794655 commit 95a4058
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ private void updateWeightFunction() {
this.indexBalanceFactor,
this.shardBalanceFactor,
this.preferPrimaryShardRebalanceBuffer,
this.primaryConstraintThreshold
this.primaryConstraintThreshold,
this.preferPrimaryShardBalance
);
}

Expand All @@ -319,9 +320,7 @@ private void updateWeightFunction() {
*/
private void setPreferPrimaryShardBalance(boolean preferPrimaryShardBalance) {
this.preferPrimaryShardBalance = preferPrimaryShardBalance;
this.weightFunction.updateAllocationConstraint(INDEX_PRIMARY_SHARD_BALANCE_CONSTRAINT_ID, preferPrimaryShardBalance);
this.weightFunction.updateAllocationConstraint(CLUSTER_PRIMARY_SHARD_BALANCE_CONSTRAINT_ID, preferPrimaryShardBalance);
this.weightFunction.updateRebalanceConstraint(INDEX_PRIMARY_SHARD_BALANCE_CONSTRAINT_ID, preferPrimaryShardBalance);
this.weightFunction.updatePrimaryShardBalanceConstraints(preferPrimaryShardBalance);
}

private void setPreferPrimaryShardRebalance(boolean preferPrimaryShardRebalance) {
Expand Down Expand Up @@ -514,7 +513,7 @@ static class WeightFunction {
private AllocationConstraints constraints;
private RebalanceConstraints rebalanceConstraints;

WeightFunction(float indexBalance, float shardBalance, float preferPrimaryBalanceBuffer, long primaryConstraintThreshold) {
WeightFunction(float indexBalance, float shardBalance, float preferPrimaryBalanceBuffer, long primaryConstraintThreshold, boolean preferPrimaryShardBalance) {
float sum = indexBalance + shardBalance;
if (sum <= 0.0f) {
throw new IllegalArgumentException("Balance factors must sum to a value > 0 but was: " + sum);
Expand All @@ -529,6 +528,8 @@ static class WeightFunction {
this.rebalanceConstraints = new RebalanceConstraints(rebalanceParameter);
// Enable index shard per node breach constraint
updateAllocationConstraint(INDEX_SHARD_PER_NODE_BREACH_CONSTRAINT_ID, true);
// Set primary shard balance constraints
updatePrimaryShardBalanceConstraints(preferPrimaryShardBalance);
}

public float weightWithAllocationConstraints(ShardsBalancer balancer, ModelNode node, String index) {
Expand Down Expand Up @@ -558,6 +559,12 @@ void updateRebalanceConstraint(String constraint, boolean add) {
void updatePrimaryConstraintThreshold(long primaryConstraintThreshold) {
this.primaryConstraintThreshold = primaryConstraintThreshold;
}

void updatePrimaryShardBalanceConstraints(boolean preferPrimaryShardBalance) {
updateAllocationConstraint(INDEX_PRIMARY_SHARD_BALANCE_CONSTRAINT_ID, preferPrimaryShardBalance);
updateAllocationConstraint(CLUSTER_PRIMARY_SHARD_BALANCE_CONSTRAINT_ID, preferPrimaryShardBalance);
updateRebalanceConstraint(INDEX_PRIMARY_SHARD_BALANCE_CONSTRAINT_ID, preferPrimaryShardBalance);
}
}

/**
Expand Down

0 comments on commit 95a4058

Please sign in to comment.