Skip to content

Commit

Permalink
[fix] [bk-client] Fix bk client MinNumRacksPerWriteQuorum and Enforce…
Browse files Browse the repository at this point in the history
…MinNumRacksPerWriteQuorum not work problem. (apache#21327)

(cherry picked from commit 61a7adf)
  • Loading branch information
horizonzy authored and shibd committed Oct 23, 2023
1 parent 992987b commit 51f56a7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,17 @@ static void setDefaultEnsemblePlacementPolicy(
}
}

private void setEnsemblePlacementPolicy(ClientConfiguration bkConf, ServiceConfiguration conf, MetadataStore store,
static void setEnsemblePlacementPolicy(ClientConfiguration bkConf, ServiceConfiguration conf, MetadataStore store,
Class<? extends EnsemblePlacementPolicy> policyClass) {
bkConf.setEnsemblePlacementPolicy(policyClass);
bkConf.setProperty(BookieRackAffinityMapping.METADATA_STORE_INSTANCE, store);
if (conf.isBookkeeperClientRackawarePolicyEnabled() || conf.isBookkeeperClientRegionawarePolicyEnabled()) {
bkConf.setProperty(REPP_DNS_RESOLVER_CLASS, conf.getProperties().getProperty(REPP_DNS_RESOLVER_CLASS,
BookieRackAffinityMapping.class.getName()));

bkConf.setMinNumRacksPerWriteQuorum(conf.getBookkeeperClientMinNumRacksPerWriteQuorum());
bkConf.setEnforceMinNumRacksPerWriteQuorum(conf.isBookkeeperClientEnforceMinNumRacksPerWriteQuorum());

bkConf.setProperty(NET_TOPOLOGY_SCRIPT_FILE_NAME_KEY,
conf.getProperties().getProperty(
NET_TOPOLOGY_SCRIPT_FILE_NAME_KEY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.apache.pulsar.metadata.api.MetadataStore;
import org.apache.pulsar.metadata.api.extended.MetadataStoreExtended;
import org.powermock.reflect.Whitebox;
import org.apache.pulsar.zookeeper.ZkIsolatedBookieEnsemblePlacementPolicy;
import org.testng.annotations.Test;

/**
Expand Down Expand Up @@ -152,6 +153,24 @@ public void testSetDefaultEnsemblePlacementPolicyRackAwareEnabledChangedValues()
assertEquals(20, bkConf.getMinNumRacksPerWriteQuorum());
}

@Test
public void testSetEnsemblePlacementPolicys() {
ClientConfiguration bkConf = new ClientConfiguration();
ServiceConfiguration conf = new ServiceConfiguration();
conf.setBookkeeperClientMinNumRacksPerWriteQuorum(3);
conf.setBookkeeperClientEnforceMinNumRacksPerWriteQuorum(true);

MetadataStore store = mock(MetadataStore.class);

BookKeeperClientFactoryImpl.setEnsemblePlacementPolicy(
bkConf,
conf,
store,
ZkIsolatedBookieEnsemblePlacementPolicy.class);
assertEquals(bkConf.getMinNumRacksPerWriteQuorum(), 3);
assertTrue(bkConf.getEnforceMinNumRacksPerWriteQuorum());
}

@Test
public void testSetDiskWeightBasedPlacementEnabled() {
BookKeeperClientFactoryImpl factory = new BookKeeperClientFactoryImpl();
Expand Down

0 comments on commit 51f56a7

Please sign in to comment.