Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<DiscoveryNode, NodeAllocationStatsAndWeight> filteredNodeAllocationStatsAndWeights = new HashMap<>(
nodesStatsAndWeights.size()
);
for (var nodeStatsAndWeight : nodesStatsAndWeights.entrySet()) {
Map<DiscoveryNode, NodeAllocationStatsAndWeight> 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());
}
Comment on lines -188 to -190
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nodesAllocationStatsAndWeights uses RoutingNodes, but RoutingNode can have at most one DiscoveryNode or null (I'm looking at Nullable node property). Potentially allocation.nodes().get(nodeStatsAndWeight.getKey()); might return null when RoutingNode does not have DiscoveryNode specified, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into it. Following the allocation.routingNodes() and allocation.nodes() methods down, it looks like the routing nodes are instantiated here. It looks reasonable that the routing nodes has all of the nodes, from this code, but there are no interface guarantees that I see to feel good about that conclusion..

Looks like the Nullable was added in this commit, probably as a performance edge case.

Eh. I feel like it should have all the nodes, but also there are no guarantees around that, so this change probably isn't safe as the RoutingNodes code is today.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to pursue this PR or close it?

assert node != null;
nodeToStatsAndWeights.put(node, nodeStatsAndWeight.getValue());
}
desiredBalanceMetrics.updateMetrics(allocationStats, desiredBalance.weightsPerNode(), filteredNodeAllocationStatsAndWeights);
desiredBalanceMetrics.updateMetrics(allocationStats, desiredBalance.weightsPerNode(), nodeToStatsAndWeights);
}

private boolean allocateUnassignedInvariant() {
Expand Down