From 9dfb33193eedcc9e3f0c66d311746b53b2446f5e Mon Sep 17 00:00:00 2001 From: Pooya Salehi Date: Wed, 6 Nov 2024 19:20:54 +0100 Subject: [PATCH] Refactor hasComputationConverged (#116331) See https://github.com/elastic/elasticsearch/pull/115511#discussion_r1831032228. --- .../allocation/allocator/DesiredBalanceComputer.java | 6 +++--- .../allocator/DesiredBalanceShardsAllocatorTests.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceComputer.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceComputer.java index 44794b70a41b9..42240a996c531 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceComputer.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceComputer.java @@ -335,7 +335,7 @@ public DesiredBalance compute( nextReportTime = currentTime + timeWarningInterval; } - if (hasComputationConverged(hasChanges, i)) { + if (hasChanges == false && hasEnoughIterations(i)) { logger.debug( "Desired balance computation for [{}] converged after [{}] and [{}] iterations", desiredBalanceInput.index(), @@ -415,8 +415,8 @@ public DesiredBalance compute( } // visible for testing - boolean hasComputationConverged(boolean hasRoutingChanges, int currentIteration) { - return hasRoutingChanges == false; + boolean hasEnoughIterations(int currentIteration) { + return true; } private static Map collectShardAssignments(RoutingNodes routingNodes) { diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceShardsAllocatorTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceShardsAllocatorTests.java index cd0d1e8a180dd..27c430131ff07 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceShardsAllocatorTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceShardsAllocatorTests.java @@ -408,8 +408,8 @@ public DesiredBalance compute( } @Override - boolean hasComputationConverged(boolean hasRoutingChanges, int currentIteration) { - return super.hasComputationConverged(hasRoutingChanges, currentIteration) && currentIteration >= minIterations; + boolean hasEnoughIterations(int currentIteration) { + return currentIteration >= minIterations; } }, reconcileAction,