Skip to content

Commit 160d763

Browse files
Small for-loop cleanup
1 parent 825b5de commit 160d763

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconciler.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,22 +174,21 @@ void run() {
174174
}
175175

176176
private void updateDesireBalanceMetrics(AllocationStats allocationStats) {
177-
var nodesStatsAndWeights = nodeAllocationStatsAndWeightsCalculator.nodesAllocationStatsAndWeights(
177+
var nodeIDsToStatsAndWeights = nodeAllocationStatsAndWeightsCalculator.nodesAllocationStatsAndWeights(
178178
allocation.metadata(),
179179
allocation.routingNodes(),
180180
allocation.clusterInfo(),
181181
desiredBalance
182182
);
183-
Map<DiscoveryNode, NodeAllocationStatsAndWeight> filteredNodeAllocationStatsAndWeights = new HashMap<>(
184-
nodesStatsAndWeights.size()
183+
Map<DiscoveryNode, NodeAllocationStatsAndWeight> nodeToStatsAndWeights = new HashMap<>(
184+
nodeIDsToStatsAndWeights.size()
185185
);
186-
for (var nodeStatsAndWeight : nodesStatsAndWeights.entrySet()) {
186+
for (var nodeStatsAndWeight : nodeIDsToStatsAndWeights.entrySet()) {
187187
var node = allocation.nodes().get(nodeStatsAndWeight.getKey());
188-
if (node != null) {
189-
filteredNodeAllocationStatsAndWeights.put(node, nodeStatsAndWeight.getValue());
190-
}
188+
assert node != null;
189+
nodeToStatsAndWeights.put(node, nodeStatsAndWeight.getValue());
191190
}
192-
desiredBalanceMetrics.updateMetrics(allocationStats, desiredBalance.weightsPerNode(), filteredNodeAllocationStatsAndWeights);
191+
desiredBalanceMetrics.updateMetrics(allocationStats, desiredBalance.weightsPerNode(), nodeToStatsAndWeights);
193192
}
194193

195194
private boolean allocateUnassignedInvariant() {

0 commit comments

Comments
 (0)