From 160d763c60ed5a9bbc15a6119c8ca287e7f36786 Mon Sep 17 00:00:00 2001 From: Dianna Hohensee Date: Tue, 14 Jan 2025 10:46:36 -0500 Subject: [PATCH 1/2] Small for-loop cleanup --- .../allocator/DesiredBalanceReconciler.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconciler.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconciler.java index 909a7a7a99a61..2f6c9200e0762 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconciler.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconciler.java @@ -174,22 +174,21 @@ void run() { } private void updateDesireBalanceMetrics(AllocationStats allocationStats) { - var nodesStatsAndWeights = nodeAllocationStatsAndWeightsCalculator.nodesAllocationStatsAndWeights( + var nodeIDsToStatsAndWeights = nodeAllocationStatsAndWeightsCalculator.nodesAllocationStatsAndWeights( allocation.metadata(), allocation.routingNodes(), allocation.clusterInfo(), desiredBalance ); - Map filteredNodeAllocationStatsAndWeights = new HashMap<>( - nodesStatsAndWeights.size() + Map nodeToStatsAndWeights = new HashMap<>( + nodeIDsToStatsAndWeights.size() ); - for (var nodeStatsAndWeight : nodesStatsAndWeights.entrySet()) { + for (var nodeStatsAndWeight : nodeIDsToStatsAndWeights.entrySet()) { var node = allocation.nodes().get(nodeStatsAndWeight.getKey()); - if (node != null) { - filteredNodeAllocationStatsAndWeights.put(node, nodeStatsAndWeight.getValue()); - } + assert node != null; + nodeToStatsAndWeights.put(node, nodeStatsAndWeight.getValue()); } - desiredBalanceMetrics.updateMetrics(allocationStats, desiredBalance.weightsPerNode(), filteredNodeAllocationStatsAndWeights); + desiredBalanceMetrics.updateMetrics(allocationStats, desiredBalance.weightsPerNode(), nodeToStatsAndWeights); } private boolean allocateUnassignedInvariant() { From 7b356d40020318311e014a60d013642ea1ae98e8 Mon Sep 17 00:00:00 2001 From: elasticsearchmachine Date: Tue, 14 Jan 2025 15:55:07 +0000 Subject: [PATCH 2/2] [CI] Auto commit changes from spotless --- .../allocation/allocator/DesiredBalanceReconciler.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconciler.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconciler.java index 2f6c9200e0762..49d1743b9a09b 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconciler.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconciler.java @@ -180,9 +180,7 @@ private void updateDesireBalanceMetrics(AllocationStats allocationStats) { allocation.clusterInfo(), desiredBalance ); - Map nodeToStatsAndWeights = new HashMap<>( - nodeIDsToStatsAndWeights.size() - ); + Map nodeToStatsAndWeights = new HashMap<>(nodeIDsToStatsAndWeights.size()); for (var nodeStatsAndWeight : nodeIDsToStatsAndWeights.entrySet()) { var node = allocation.nodes().get(nodeStatsAndWeight.getKey()); assert node != null;