szetszwo commented on code in PR #5666:
URL: https://github.com/apache/ozone/pull/5666#discussion_r1416576491
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMBlockProtocolServer.java:
##########
@@ -198,6 +201,13 @@ public List<AllocatedBlock> allocateBlock(
.allocateBlock(size, replicationConfig, owner, excludeList);
if (block != null) {
blocks.add(block);
+ // Sort the datanodes if client machine is specified
+ if (StringUtils.isNotEmpty(clientMachine)) {
+ List<String> uuidList = HddsUtils.toNodeUuid(
+ block.getPipeline().getNodes());
+ block.getPipeline().setNodesInOrder(
+ sortDatanodes(uuidList, clientMachine));
Review Comment:
Sort the datanode directly:
```java
@@ -200,6 +203,14 @@ public List<AllocatedBlock> allocateBlock(
.allocateBlock(size, replicationConfig, owner, excludeList);
if (block != null) {
blocks.add(block);
+ // Sort the datanodes if client machine is specified
+ final Node client = getClientNode(clientMachine);
+ if (client != null) {
+ final List<DatanodeDetails> nodes =
block.getPipeline().getNodes();
+ final List<DatanodeDetails> sorted = scm.getClusterMap()
+ .sortByDistanceCost(client, nodes, nodes.size());
+ block.getPipeline().setNodesInOrder(sorted);
+ }
}
}
@@ -347,11 +358,7 @@ public List<DatanodeDetails> sortDatanodes(List<String>
nodes,
auditMap.put("nodes", String.valueOf(nodes));
try {
NodeManager nodeManager = scm.getScmNodeManager();
- Node client = getDatanode(clientMachine);
- // not datanode
- if (client == null) {
- client = getOtherNode(clientMachine);
- }
+ final Node client = getClientNode(clientMachine);
List<DatanodeDetails> nodeList = new ArrayList<>();
nodes.forEach(uuid -> {
DatanodeDetails node = nodeManager.getNodeByUuid(uuid);
@@ -376,10 +383,10 @@ public List<DatanodeDetails>
sortDatanodes(List<String> nodes,
}
}
- private Node getDatanode(String clientMachine) {
+ private Node getClientNode(String clientMachine) {
List<DatanodeDetails> datanodes = scm.getScmNodeManager()
.getNodesByAddress(clientMachine);
- return !datanodes.isEmpty() ? datanodes.get(0) : null;
+ return !datanodes.isEmpty() ? datanodes.get(0) :
getOtherNode(clientMachine);
}
private Node getOtherNode(String clientMachine) {
```
--
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]