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


##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/client/RegionAwareEnsemblePlacementPolicy.java:
##########
@@ -644,12 +645,75 @@ public final DistributionSchedule.WriteSet 
reorderReadLACSequence(
     @Override
     public PlacementPolicyAdherence 
isEnsembleAdheringToPlacementPolicy(List<BookieId> ensembleList,
             int writeQuorumSize, int ackQuorumSize) {
-        /**
-         * TODO: have to implement actual logic for this method for
-         * RegionAwareEnsemblePlacementPolicy. For now return true value.
-         *
-         * - https://github.com/apache/bookkeeper/issues/1898
-         */
+        if (CollectionUtils.isEmpty(ensembleList)) {
+            return PlacementPolicyAdherence.FAIL;
+        }
+
+        int effectiveMinRegionsForDurability = 
disableDurabilityFeature.isAvailable() ? 1 : minRegionsForDurability;
+
+        int ensembleSize = ensembleList.size();
+        Map<String, Set<BookieId>> regionsInQuorum = new HashMap<>();
+        BookieId bookie;
+        for (int i = 0; i < ensembleList.size(); i++) {
+            regionsInQuorum.clear();
+            for (int j = 0; j < writeQuorumSize; j++) {
+                bookie = ensembleList.get((i + j) % ensembleSize);
+                if (knownBookies.containsKey(bookie)) {
+                    String region = getLocalRegion(knownBookies.get(bookie));
+                    if (regionsInQuorum.containsKey(region)) {
+                        regionsInQuorum.get(region).add(bookie);
+                    } else {
+                        Set<BookieId> bookieSet = new HashSet<>();
+                        bookieSet.add(bookie);
+                        regionsInQuorum.put(region, bookieSet);
+                    }
+                } else if (LOG.isDebugEnabled()) {
+                    LOG.debug("bookie {} is not in the list of knownBookies", 
bookie);
+                }
+            }
+
+            if (regionsInQuorum.isEmpty()) {
+                return PlacementPolicyAdherence.FAIL;
+            }
+
+            if (regionsInQuorum.size() < 2) {

Review Comment:
   It's a little weird. 
   Based on: writeQuorumSize = 3.
   
   If regionsInQuorum < 2, the result may be `MEETS_STRICT`.
   
   If regionsInQuorum = 2, the result is `FAIL`.



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