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..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 @@ -174,22 +174,19 @@ 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() - ); - for (var nodeStatsAndWeight : nodesStatsAndWeights.entrySet()) { + Map nodeToStatsAndWeights = new HashMap<>(nodeIDsToStatsAndWeights.size()); + 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() {