Skip to content

Commit 761adc3

Browse files
committed
Tuning constraints
Signed-off-by: Arpit Bandejiya <abandeji@amazon.com>
1 parent a2eaddd commit 761adc3

File tree

4 files changed

+6
-3
lines changed

4 files changed

+6
-3
lines changed

server/src/main/java/org/opensearch/cluster/routing/allocation/ConstraintTypes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static Predicate<Constraint.ConstraintParams> isPrimaryShardsPerNodeBreac
9191
return (params) -> {
9292
int primaryShardCount = params.getNode().numPrimaryShards();
9393
int allowedPrimaryShardCount = (int) Math.ceil(params.getBalancer().avgPrimaryShardsPerNode() * (1 + buffer));
94-
return primaryShardCount >= allowedPrimaryShardCount;
94+
return primaryShardCount > allowedPrimaryShardCount;
9595
};
9696
}
9797
}

server/src/main/java/org/opensearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ public BalancedShardsAllocator(Settings settings) {
169169

170170
@Inject
171171
public BalancedShardsAllocator(Settings settings, ClusterSettings clusterSettings) {
172+
setIndexBalanceFactor(INDEX_BALANCE_FACTOR_SETTING.get(settings));
173+
setShardBalanceFactor(SHARD_BALANCE_FACTOR_SETTING.get(settings));
174+
setPreferPrimaryShardBalanceBuffer(PREFER_PRIMARY_SHARD_BALANCE_BUFFER.get(settings));
172175
setWeightFunction(
173176
INDEX_BALANCE_FACTOR_SETTING.get(settings),
174177
SHARD_BALANCE_FACTOR_SETTING.get(settings),
@@ -177,7 +180,6 @@ public BalancedShardsAllocator(Settings settings, ClusterSettings clusterSetting
177180
setThreshold(THRESHOLD_SETTING.get(settings));
178181
setPreferPrimaryShardBalance(PREFER_PRIMARY_SHARD_BALANCE.get(settings));
179182
setShardMovementStrategy(SHARD_MOVEMENT_STRATEGY_SETTING.get(settings));
180-
setPreferPrimaryShardBalanceBuffer(PREFER_PRIMARY_SHARD_BALANCE_BUFFER.get(settings));
181183
clusterSettings.addSettingsUpdateConsumer(PREFER_PRIMARY_SHARD_BALANCE, this::setPreferPrimaryShardBalance);
182184
clusterSettings.addSettingsUpdateConsumer(SHARD_MOVE_PRIMARY_FIRST_SETTING, this::setMovePrimaryFirst);
183185
clusterSettings.addSettingsUpdateConsumer(SHARD_MOVEMENT_STRATEGY_SETTING, this::setShardMovementStrategy);

server/src/main/java/org/opensearch/cluster/routing/allocation/allocator/LocalShardsBalancer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ private boolean tryRelocateShard(BalancedShardsAllocator.ModelNode minNode, Bala
998998
// doing such relocation wouldn't help in primary balance.
999999
if (preferPrimaryBalance == true
10001000
&& shard.primary()
1001-
&& maxNode.numPrimaryShards(shard.getIndexName()) - minNode.numPrimaryShards(shard.getIndexName()) < 2) {
1001+
&& maxNode.numPrimaryShards() - minNode.numPrimaryShards() < 2) {
10021002
continue;
10031003
}
10041004

server/src/main/java/org/opensearch/common/settings/ClusterSettings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ public void apply(Settings value, Settings current, Settings previous) {
248248
AwarenessReplicaBalance.CLUSTER_ROUTING_ALLOCATION_AWARENESS_BALANCE_SETTING,
249249
BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING,
250250
BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING,
251+
BalancedShardsAllocator.PREFER_PRIMARY_SHARD_BALANCE_BUFFER,
251252
BalancedShardsAllocator.PREFER_PRIMARY_SHARD_BALANCE,
252253
BalancedShardsAllocator.SHARD_MOVE_PRIMARY_FIRST_SETTING,
253254
BalancedShardsAllocator.SHARD_MOVEMENT_STRATEGY_SETTING,

0 commit comments

Comments
 (0)