adoroszlai commented on code in PR #11981:
URL: https://github.com/apache/ozone/pull/11981#discussion_r4573955238
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/placement/algorithms/SCMContainerPlacementRackAware.java:
##########
@@ -255,6 +257,14 @@ protected List<DatanodeDetails> chooseDatanodesInternal(
mutableUsedNodes, favorIndex, nodesRequired, mapSizeRequired);
}
+ private static int countUnavailableNodes(List<DatanodeDetails> usedNodes,
List<DatanodeDetails> excludedNodes) {
+ Set<DatanodeDetails> unavailableNodes = new HashSet<>(usedNodes);
+ if (excludedNodes != null) {
+ unavailableNodes.addAll(excludedNodes);
+ }
+ return unavailableNodes.size();
Review Comment:
Need to copy only if `excludedNodes != null`.
```suggestion
if (excludedNodes == null || excludedNodes.isEmpty()) {
return usedNodes.size();
}
Set<DatanodeDetails> unavailableNodes = new HashSet<>(usedNodes.size() +
excludedNodes.size(), 1);
unavailableNodes.addAll(usedNodes);
unavailableNodes.addAll(excludedNodes);
return unavailableNodes.size();
```
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/placement/algorithms/SCMContainerPlacementRackAware.java:
##########
@@ -120,7 +122,7 @@ protected List<DatanodeDetails> chooseDatanodesInternal(
int datanodeCount = networkTopology.getNumOfLeafNode(NetConstants.ROOT);
int excludedNodesCount = excludedNodes == null ? 0 : excludedNodes.size();
int usedNodesCount = usedNodes == null ? 0 : usedNodes.size();
- if (datanodeCount < nodesRequired + excludedNodesCount + usedNodesCount) {
+ if (datanodeCount < nodesRequired + countUnavailableNodes(usedNodes,
excludedNodes)) {
Review Comment:
Please save return value in variable and include in the exception message.
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/placement/algorithms/SCMContainerPlacementRackAware.java:
##########
@@ -120,7 +122,7 @@ protected List<DatanodeDetails> chooseDatanodesInternal(
int datanodeCount = networkTopology.getNumOfLeafNode(NetConstants.ROOT);
int excludedNodesCount = excludedNodes == null ? 0 : excludedNodes.size();
int usedNodesCount = usedNodes == null ? 0 : usedNodes.size();
- if (datanodeCount < nodesRequired + excludedNodesCount + usedNodesCount) {
+ if (datanodeCount < nodesRequired + countUnavailableNodes(usedNodes,
excludedNodes)) {
throw new SCMException("No enough datanodes to choose. " +
Review Comment:
nit: finally we can fix this typo, too:
```suggestion
throw new SCMException("Not enough datanodes to choose. " +
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]