dragonls commented on code in PR #4133:
URL: https://github.com/apache/bookkeeper/pull/4133#discussion_r1431314751
##########
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:
The purpose of doing this here is to align the implement in
`org.apache.bookkeeper.client.RegionAwareEnsemblePlacementPolicy#newEnsemble`:
https://github.com/apache/bookkeeper/blob/185fef6df92713a92f1531a4044f75ffebcc6e93/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/RegionAwareEnsemblePlacementPolicy.java#L356-L366
When there is only one available region, fall back to
`RackAwareEnsemblePlacement`.
--
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]