From 226a9b0ed829be81046612d626d19eaacec094bd Mon Sep 17 00:00:00 2001 From: zhangshuyan Date: Mon, 16 Oct 2023 18:03:03 +0800 Subject: [PATCH] HDFS-17227. EC: Fix bug in choosing targets when racks is not enough. --- .../BlockPlacementPolicyRackFaultTolerant.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyRackFaultTolerant.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyRackFaultTolerant.java index 8a7ef134e4fca..b3f01e7ad559b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyRackFaultTolerant.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockPlacementPolicyRackFaultTolerant.java @@ -172,25 +172,20 @@ private void chooseEvenlyFromRemainingRacks(Node writer, while (results.size() != totalReplicaExpected && bestEffortMaxNodesPerRack < totalReplicaExpected) { // Exclude the chosen nodes - final Set newExcludeNodes = new HashSet<>(); for (DatanodeStorageInfo resultStorage : results) { - addToExcludedNodes(resultStorage.getDatanodeDescriptor(), - newExcludeNodes); + addToExcludedNodes(resultStorage.getDatanodeDescriptor(), excludedNodes); } LOG.trace("Chosen nodes: {}", results); LOG.trace("Excluded nodes: {}", excludedNodes); - LOG.trace("New Excluded nodes: {}", newExcludeNodes); final int numOfReplicas = totalReplicaExpected - results.size(); numResultsOflastChoose = results.size(); try { - chooseOnce(numOfReplicas, writer, newExcludeNodes, blocksize, + chooseOnce(numOfReplicas, writer, excludedNodes, blocksize, ++bestEffortMaxNodesPerRack, results, avoidStaleNodes, storageTypes); } catch (NotEnoughReplicasException nere) { lastException = nere; - } finally { - excludedNodes.addAll(newExcludeNodes); } // To improve performance, the maximum value of 'bestEffortMaxNodesPerRack' // is calculated only when it is not possible to select a node.