zhangshuyan0 commented on PR #5759: URL: https://github.com/apache/hadoop/pull/5759#issuecomment-1608786418
@zhtttylz How about combining the above two solutions? May avoid the drawbacks of both options. ``` private void chooseEvenlyFromRemainingRacks(Node writer, Set<Node> excludedNodes, long blocksize, int maxNodesPerRack, List<DatanodeStorageInfo> results, boolean avoidStaleNodes, EnumMap<StorageType, Integer> storageTypes, int totalReplicaExpected, NotEnoughReplicasException e) throws NotEnoughReplicasException { int numResultsOflastChoose = 0; NotEnoughReplicasException lastException = e; int bestEffortMaxNodesPerRack = maxNodesPerRack; while (results.size() != totalReplicaExpected && bestEffortMaxNodesPerRack < totalReplicaExpected) { // Exclude the chosen nodes final Set<Node> newExcludeNodes = new HashSet<>(); for (DatanodeStorageInfo resultStorage : results) { addToExcludedNodes(resultStorage.getDatanodeDescriptor(), newExcludeNodes); } 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, ++bestEffortMaxNodesPerRack, results, avoidStaleNodes, storageTypes); } catch (NotEnoughReplicasException nere) { lastException = nere; } finally { excludedNodes.addAll(newExcludeNodes); } if (numResultsOflastChoose == results.size()) { Map<String, Integer> nodesPerRack = new HashMap<>(); for (DatanodeStorageInfo dsInfo : results) { String rackName = dsInfo.getDatanodeDescriptor().getNetworkLocation(); nodesPerRack.merge(rackName, 1, Integer::sum); } for (int numNodes : nodesPerRack.values()) { if (numNodes > bestEffortMaxNodesPerRack) { bestEffortMaxNodesPerRack = numNodes; } } } } if (numResultsOflastChoose != totalReplicaExpected) { LOG.debug("Best effort placement failed: expecting {} replicas, only " + "chose {}.", totalReplicaExpected, numResultsOflastChoose); throw lastException; } } ``` -- 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: common-issues-unsubscr...@hadoop.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-issues-h...@hadoop.apache.org