hangc0276 commented on code in PR #3721:
URL: https://github.com/apache/bookkeeper/pull/3721#discussion_r1059217690


##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/client/RackawareEnsemblePlacementPolicyImpl.java:
##########
@@ -414,21 +414,52 @@ protected PlacementResult<List<BookieId>> 
newEnsembleInternal(
                 }
                 return PlacementResult.of(addrs, 
PlacementPolicyAdherence.FAIL);
             }
-
-            for (int i = 0; i < ensembleSize; i++) {
-                String curRack;
-                if (null == prevNode) {
-                    if ((null == localNode) || 
defaultRack.equals(localNode.getNetworkLocation())) {
-                        curRack = NodeBase.ROOT;
+            try {
+                //Choose different rack nodes.
+                String curRack = null;
+                for (int i = 0; i < ensembleSize; i++) {
+                    if (null == prevNode) {
+                        if ((null == localNode) || 
defaultRack.equals(localNode.getNetworkLocation())) {
+                            curRack = NodeBase.ROOT;
+                        } else {
+                            curRack = localNode.getNetworkLocation();
+                        }
                     } else {
-                        curRack = localNode.getNetworkLocation();
+                        if (!curRack.startsWith("~")) {
+                            curRack = "~" + prevNode.getNetworkLocation();
+                        } else {
+                            curRack = curRack + 
NetworkTopologyImpl.NODE_SEPARATOR + prevNode.getNetworkLocation();
+                        }
                     }
-                } else {
-                    curRack = "~" + prevNode.getNetworkLocation();
+                    prevNode = selectRandomFromRack(curRack, excludeNodes, 
ensemble, ensemble);

Review Comment:
   Can we set `fallbackRandom` flag in `selectRandomFromRack` to support random 
selection instead of random select in BKNotEnoughBookiesException



-- 
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]

Reply via email to