You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by "dragonls (via GitHub)" <gi...@apache.org> on 2024/02/05 03:12:02 UTC

Re: [PR] Issue 1898: Implement `isEnsembleAdheringToPlacementPolicy` in `RegionAwareEnsemblePlacementPolicy` [bookkeeper]

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


##########
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:
   Updated.



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