Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix primary balance flaky test #8366

Merged
merged 1 commit into from
Jun 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public void testGlobalPrimaryAllocation() throws Exception {
* This test in general passes without primary shard balance as well due to nature of allocation algorithm which
* assigns all primary shards first followed by replica copies.
*/
@AwaitsFix(bugUrl = "https://github.com/opensearch-project/OpenSearch/issues/7751")
public void testPerIndexPrimaryAllocation() throws Exception {
internalCluster().startClusterManagerOnlyNode();
final int maxReplicaCount = 2;
Expand Down Expand Up @@ -234,7 +233,7 @@ private void verifyPerIndexPrimaryBalance() throws Exception {
RoutingNodes nodes = currentState.getRoutingNodes();
for (final Map.Entry<String, IndexRoutingTable> index : currentState.getRoutingTable().indicesRouting().entrySet()) {
final int totalPrimaryShards = index.getValue().primaryShardsActive();
final int avgPrimaryShardsPerNode = (int) Math.ceil(totalPrimaryShards * 1f / currentState.getRoutingNodes().size());
final int avgPrimaryShardsPerNode = (int) Math.floor(totalPrimaryShards * 1f / currentState.getRoutingNodes().size());
for (RoutingNode node : nodes) {
final int primaryCount = node.shardsWithState(index.getKey(), STARTED)
.stream()
Expand All @@ -250,7 +249,8 @@ private void verifyPerIndexPrimaryBalance() throws Exception {
avgPrimaryShardsPerNode
);
}
assertTrue(primaryCount <= avgPrimaryShardsPerNode);
// Asserts value is within the variance threshold (-1/+1 of the average value).
assertTrue(avgPrimaryShardsPerNode - 1 <= primaryCount && primaryCount <= avgPrimaryShardsPerNode + 1);
}
}
}, 60, TimeUnit.SECONDS);
Expand Down