Skip to content

Commit cfcde88

Browse files
committed
Fix constraint bug which allows more primary shards than average primary shards per index
Signed-off-by: Gaurav Bafna <[email protected]>
1 parent f85a58f commit cfcde88

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
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
@@ -70,7 +70,7 @@ public static Predicate<Constraint.ConstraintParams> isPerIndexPrimaryShardsPerN
7070
return (params) -> {
7171
int perIndexPrimaryShardCount = params.getNode().numPrimaryShards(params.getIndex());
7272
int perIndexAllowedPrimaryShardCount = (int) Math.ceil(params.getBalancer().avgPrimaryShardsPerNode(params.getIndex()));
73-
return perIndexPrimaryShardCount > perIndexAllowedPrimaryShardCount;
73+
return perIndexPrimaryShardCount >= perIndexAllowedPrimaryShardCount;
7474
};
7575
}
7676

server/src/test/java/org/opensearch/cluster/routing/allocation/AllocationConstraintsTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void testPerIndexPrimaryShardsConstraint() {
9393

9494
assertEquals(0, constraints.weight(balancer, node, indexName));
9595

96-
perIndexPrimaryShardCount = 3;
96+
perIndexPrimaryShardCount = 2;
9797
when(node.numPrimaryShards(anyString())).thenReturn(perIndexPrimaryShardCount);
9898
assertEquals(CONSTRAINT_WEIGHT, constraints.weight(balancer, node, indexName));
9999

0 commit comments

Comments
 (0)