You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2023/01/07 02:19:16 UTC

[GitHub] [bookkeeper] horizonzy commented on a diff in pull request #3721: New ensemble choose different rack first.

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


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

Review Comment:
   Use `selectRandomFromRack` instead of `selectFromNetworkLocation`.
   There are two reasons:
   1. `selectFromNetworkLocation` params `fallbackToRandom` may step down to pick a node randomly.
   2. If the user config `setNetworkTopologyStabilizePeriodSeconds`, RackawareEnsemblePlacementPolicy#selectFromNetworkLocation may step down to pick node from slave.
   
   We should avoid it, just pick different node without steping down.



-- 
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: commits-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org