Skip to content

Issue 1898: Implement isEnsembleAdheringToPlacementPolicy in RegionAwareEnsemblePlacementPolicy #4133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.apache.bookkeeper.proto.BookieAddressResolver;
import org.apache.bookkeeper.stats.StatsLogger;
import org.apache.bookkeeper.util.BookKeeperConstants;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a question: why judge the regionsInQuorum.size() < 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of doing this here is to align the implement in org.apache.bookkeeper.client.RegionAwareEnsemblePlacementPolicy#newEnsemble:

// Single region, fall back to RackAwareEnsemblePlacement
if (numRegionsAvailable < 2) {
RRTopologyAwareCoverageEnsemble ensemble = new RRTopologyAwareCoverageEnsemble(ensembleSize,
writeQuorumSize, ackQuorumSize, REGIONID_DISTANCE_FROM_LEAVES,
effectiveMinRegionsForDurability > 0 ? new HashSet<>(perRegionPlacement.keySet()) : null,
effectiveMinRegionsForDurability, minNumRacksPerWriteQuorum);
TopologyAwareEnsemblePlacementPolicy nextPolicy = perRegionPlacement.get(
availableRegions.iterator().next());
return nextPolicy.newEnsemble(ensembleSize, writeQuorumSize, writeQuorumSize,
comprehensiveExclusionBookiesSet, ensemble, ensemble);
}

When there is only one available region, fall back to RackAwareEnsemblePlacement.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, a little weird.

Should we just remove the numRegionsAvailable < 2 judge in isEnsembleAdheringToPlacementPolicy? May I have your suggestion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PlacementPolicyAdherence enum has three values FAIL(1), MEETS_SOFT(3), MEETS_STRICT(5).
If there are enough different region, the result could be MEETS_STRICT. If there aren't enough different region, the each RackAwarePLacementPolicy MEETS_STRICT, the result could be MEETS_SOFT

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

// fall back to use the ensemblePlacementPolicy in specific region
String region = regionsInQuorum.keySet().iterator().next();
Set<BookieId> bookieIds = regionsInQuorum.get(region);

TopologyAwareEnsemblePlacementPolicy policyWithinRegion = perRegionPlacement.get(region);
PlacementPolicyAdherence isEnsembleAdheringToPlacementPolicy = policyWithinRegion
.isEnsembleAdheringToPlacementPolicy(new ArrayList<>(bookieIds), bookieIds.size(), 1);
if (isEnsembleAdheringToPlacementPolicy == PlacementPolicyAdherence.FAIL) {
if (LOG.isDebugEnabled()) {
LOG.debug("For ensemble {}, write set starting at {} are all from one region, "
+ "fall back to RackawareEnsemblePlacementPolicy and fail.", ensembleList, i);
}
return PlacementPolicyAdherence.FAIL;
}
continue;
}

if (effectiveMinRegionsForDurability > 0 && regionsInQuorum.size() < effectiveMinRegionsForDurability) {
if (LOG.isDebugEnabled()) {
LOG.debug("For ensemble {}, write set starting at {} are from {} regions, "
+ "less than effectiveMinRegionsForDurability: {}.",
ensembleList, i, regionsInQuorum.size(), effectiveMinRegionsForDurability);
}
return PlacementPolicyAdherence.FAIL;
}

if (regionsInQuorum.size() < writeQuorumSize) {
// each writeQuorum should be different regions
if (LOG.isDebugEnabled()) {
LOG.debug("For ensemble: {}, write set starting at {} are from {} regions, "
+ "less than writeQuorumSize {}.",
ensembleList, i, regionsInQuorum.size(), writeQuorumSize);
}
return PlacementPolicyAdherence.FAIL;
}
}

return PlacementPolicyAdherence.MEETS_STRICT;
}
}
Loading