apache / apache/bookkeeper

[Bug] EnforceMinNumRacksPerWriteQuorum is not working correctly in the isEnsembleAdheringToPlacementPolicy method of RackawareEnsemblePlacementPolicyImpl

Open
#4,501 0 comments 0 reactions 0 assignees View on GitHub
type/bug
Dominant language
Java
Stars
2k
Forks
976
Avg merge
6d 15h
Merged PRs (30d)
7

Description

**BUG REPORT**

***Describe the bug***
I'm a bit confused about the meaning of the `enforceMinNumRacksPerWriteQuorum` parameter.
When I set `enforceMinNumRacksPerWriteQuorum=false` and `minNumRacksPerWriteQuorum=2`. I ran this test expecting the result to be MEETS_STRICT, but it returned FAIL. I believe that when enforceMinNumRacksPerWriteQuorum is set to false, as long as the number of selected racks is greater than 1, the result should be MEETS_STRICT.

The problem might be in the code snippet from the isEnsembleAdheringToPlacementPolicy method:
`
if ((racksInQuorum.size() < minNumRacksPerWriteQuorumForThisEnsemble)
|| (enforceMinNumRacksPerWriteQuorum && racksInQuorum.contains(getDefaultRack()))) {
return PlacementPolicyAdherence.FAIL;
}
`

The modified code, which ensures that enforceMinNumRacksPerWriteQuorum is effective, is as follows:
`
if (enforceMinNumRacksPerWriteQuorum && (racksInQuorum.size() < minNumRacksPerWriteQuorumForThisEnsemble
|| racksInQuorum.contains(getDefaultRack()))) {
return PlacementPolicyAdherence.FAIL;
}
`
***To Reproduce***

@Test
public void testIsEnsembleAdheringToPlacementPolicyWithEnableEnforceMinRacks() throws Exception {
BookieSocketAddress addr1 = new BookieSocketAddress("127.0.0.2", 3181);
BookieSocketAddress addr2 = new BookieSocketAddress("127.0.0.3", 3181);
BookieSocketAddress addr3 = new BookieSocketAddress("127.0.0.4", 3181);

StaticDNSResolver.addNodeToRack(addr1.getHostName(), "/default-region/r1");
StaticDNSResolver.addNodeToRack(addr2.getHostName(), "/default-region/r1");
StaticDNSResolver.addNodeToRack(addr3.getHostName(), "/default-region/r1");

// Update cluster
Set addrs = new HashSet();
addrs.add(addr1.toBookieId());
addrs.add(addr2.toBookieId());
addrs.add(addr3.toBookieId());
repp.onClusterChanged(addrs, new HashSet());

List ensemble = new ArrayList<>();
ensemble.add(addr1.toBookieId());
ensemble.add(addr2.toBookieId());
assertEquals("PlacementPolicyAdherence", PlacementPolicyAdherence.MEETS_STRICT,
repp.isEnsembleAdheringToPlacementPolicy(ensemble, 2, 2));
}
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

***Expected behavior***

A clear and concise description of what you expected to happen.

***Screenshots***

If applicable, add screenshots to help explain your problem.

***Additional context***

Add any other context about the problem here.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.