Skip to content

Commit

Permalink
Add lower and upper bound support for appropriate variance thresholds (
Browse files Browse the repository at this point in the history
…opensearch-project#8372)

Signed-off-by: Kunal Kotwani <kkotwani@amazon.com>
  • Loading branch information
kotwanikunal authored Jun 30, 2023
1 parent 17ee1ce commit a68733a
Showing 1 changed file with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,24 +233,30 @@ 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.floor(totalPrimaryShards * 1f / currentState.getRoutingNodes().size());
final int lowerBoundPrimaryShardsPerNode = (int) Math.floor(totalPrimaryShards * 1f / currentState.getRoutingNodes().size())
- 1;
final int upperBoundPrimaryShardsPerNode = (int) Math.ceil(totalPrimaryShards * 1f / currentState.getRoutingNodes().size())
+ 1;
for (RoutingNode node : nodes) {
final int primaryCount = node.shardsWithState(index.getKey(), STARTED)
.stream()
.filter(ShardRouting::primary)
.collect(Collectors.toList())
.size();
if (primaryCount > avgPrimaryShardsPerNode) {
logger.info(
"--> Primary shard balance assertion failure for index {} on node {} {} <= {}",
index.getKey(),
node.node().getName(),
primaryCount,
avgPrimaryShardsPerNode
);
}
// Asserts value is within the variance threshold (-1/+1 of the average value).
assertTrue(avgPrimaryShardsPerNode - 1 <= primaryCount && primaryCount <= avgPrimaryShardsPerNode + 1);
assertTrue(
"--> Primary balance assertion failure for index "
+ index
+ "on node "
+ node.node().getName()
+ " "
+ lowerBoundPrimaryShardsPerNode
+ " <= "
+ primaryCount
+ " (assigned) <= "
+ upperBoundPrimaryShardsPerNode,
lowerBoundPrimaryShardsPerNode <= primaryCount && primaryCount <= upperBoundPrimaryShardsPerNode
);
}
}
}, 60, TimeUnit.SECONDS);
Expand Down

0 comments on commit a68733a

Please sign in to comment.