Skip to content

Commit

Permalink
Tuning constraints
Browse files Browse the repository at this point in the history
Signed-off-by: Arpit Bandejiya <[email protected]>
  • Loading branch information
Arpit-Bandejiya committed Mar 14, 2024
1 parent a2eaddd commit 761adc3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static Predicate<Constraint.ConstraintParams> isPrimaryShardsPerNodeBreac
return (params) -> {
int primaryShardCount = params.getNode().numPrimaryShards();
int allowedPrimaryShardCount = (int) Math.ceil(params.getBalancer().avgPrimaryShardsPerNode() * (1 + buffer));
return primaryShardCount >= allowedPrimaryShardCount;
return primaryShardCount > allowedPrimaryShardCount;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ public BalancedShardsAllocator(Settings settings) {

@Inject
public BalancedShardsAllocator(Settings settings, ClusterSettings clusterSettings) {
setIndexBalanceFactor(INDEX_BALANCE_FACTOR_SETTING.get(settings));
setShardBalanceFactor(SHARD_BALANCE_FACTOR_SETTING.get(settings));
setPreferPrimaryShardBalanceBuffer(PREFER_PRIMARY_SHARD_BALANCE_BUFFER.get(settings));
setWeightFunction(
INDEX_BALANCE_FACTOR_SETTING.get(settings),
SHARD_BALANCE_FACTOR_SETTING.get(settings),
Expand All @@ -177,7 +180,6 @@ public BalancedShardsAllocator(Settings settings, ClusterSettings clusterSetting
setThreshold(THRESHOLD_SETTING.get(settings));
setPreferPrimaryShardBalance(PREFER_PRIMARY_SHARD_BALANCE.get(settings));
setShardMovementStrategy(SHARD_MOVEMENT_STRATEGY_SETTING.get(settings));
setPreferPrimaryShardBalanceBuffer(PREFER_PRIMARY_SHARD_BALANCE_BUFFER.get(settings));
clusterSettings.addSettingsUpdateConsumer(PREFER_PRIMARY_SHARD_BALANCE, this::setPreferPrimaryShardBalance);
clusterSettings.addSettingsUpdateConsumer(SHARD_MOVE_PRIMARY_FIRST_SETTING, this::setMovePrimaryFirst);
clusterSettings.addSettingsUpdateConsumer(SHARD_MOVEMENT_STRATEGY_SETTING, this::setShardMovementStrategy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ private boolean tryRelocateShard(BalancedShardsAllocator.ModelNode minNode, Bala
// doing such relocation wouldn't help in primary balance.
if (preferPrimaryBalance == true
&& shard.primary()
&& maxNode.numPrimaryShards(shard.getIndexName()) - minNode.numPrimaryShards(shard.getIndexName()) < 2) {
&& maxNode.numPrimaryShards() - minNode.numPrimaryShards() < 2) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ public void apply(Settings value, Settings current, Settings previous) {
AwarenessReplicaBalance.CLUSTER_ROUTING_ALLOCATION_AWARENESS_BALANCE_SETTING,
BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING,
BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING,
BalancedShardsAllocator.PREFER_PRIMARY_SHARD_BALANCE_BUFFER,
BalancedShardsAllocator.PREFER_PRIMARY_SHARD_BALANCE,
BalancedShardsAllocator.SHARD_MOVE_PRIMARY_FIRST_SETTING,
BalancedShardsAllocator.SHARD_MOVEMENT_STRATEGY_SETTING,
Expand Down

0 comments on commit 761adc3

Please sign in to comment.