You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/09/28 03:28:41 UTC

[GitHub] [pulsar] gaozhangmin commented on a change in pull request #12025: violation of isolation when using bookie affinity group

gaozhangmin commented on a change in pull request #12025:
URL: https://github.com/apache/pulsar/pull/12025#discussion_r717194515



##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java
##########
@@ -1336,22 +1340,70 @@ public void openLedgerFailed(ManagedLedgerException exception, Object ctx) {
                         );
                     }
 
-
                     ManagedLedgerConfig managedLedgerConfig = new ManagedLedgerConfig();
                     managedLedgerConfig.setEnsembleSize(persistencePolicies.getBookkeeperEnsemble());
                     managedLedgerConfig.setWriteQuorumSize(persistencePolicies.getBookkeeperWriteQuorum());
                     managedLedgerConfig.setAckQuorumSize(persistencePolicies.getBookkeeperAckQuorum());
-                    if (localPolicies.isPresent() && localPolicies.get().bookieAffinityGroup != null) {
-                        managedLedgerConfig
-                                .setBookKeeperEnsemblePlacementPolicyClassName(
-                                        ZkIsolatedBookieEnsemblePlacementPolicy.class);
-                        Map<String, Object> properties = Maps.newHashMap();
-                        properties.put(ZkIsolatedBookieEnsemblePlacementPolicy.ISOLATION_BOOKIE_GROUPS,
-                                localPolicies.get().bookieAffinityGroup.getBookkeeperAffinityGroupPrimary());
-                        properties.put(ZkIsolatedBookieEnsemblePlacementPolicy.SECONDARY_ISOLATION_BOOKIE_GROUPS,
-                                localPolicies.get().bookieAffinityGroup.getBookkeeperAffinityGroupSecondary());
-                        managedLedgerConfig.setBookKeeperEnsemblePlacementPolicyProperties(properties);
+
+                    if (serviceConfig.isStrictBookieAffinityEnabled()) {
+                        Optional<GetResult> racksData =
+                                this.pulsar.getLocalMetadataStore().
+                                        get(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH).join();
+                        if (racksData.isPresent()) {
+                            try {
+                                BookiesRackConfiguration allGroupsBookieMapping =
+                                        ObjectMapperFactory.getThreadLocal().
+                                                readValue(racksData.get().getValue(), BookiesRackConfiguration.class);
+                                if (allGroupsBookieMapping.size() > 0) {
+                                    managedLedgerConfig
+                                            .setBookKeeperEnsemblePlacementPolicyClassName(
+                                                    ZkIsolatedBookieEnsemblePlacementPolicy.class);
+                                    if (localPolicies.isPresent()
+                                            && localPolicies.get().bookieAffinityGroup != null) {
+                                        Map<String, Object> properties = Maps.newHashMap();
+                                        properties.put(ZkIsolatedBookieEnsemblePlacementPolicy
+                                                        .ISOLATION_BOOKIE_GROUPS,
+                                                localPolicies.get().bookieAffinityGroup
+                                                        .getBookkeeperAffinityGroupPrimary());
+                                        properties.put(ZkIsolatedBookieEnsemblePlacementPolicy
+                                                        .SECONDARY_ISOLATION_BOOKIE_GROUPS,
+                                                localPolicies.get().bookieAffinityGroup
+                                                        .getBookkeeperAffinityGroupSecondary());
+                                        managedLedgerConfig.
+                                                setBookKeeperEnsemblePlacementPolicyProperties(properties);
+                                    } else {
+                                        Map<String, Object> properties = Maps.newHashMap();
+                                        properties.put(ZkIsolatedBookieEnsemblePlacementPolicy
+                                                .ISOLATION_BOOKIE_GROUPS, "");
+                                        properties.put(ZkIsolatedBookieEnsemblePlacementPolicy
+                                                .SECONDARY_ISOLATION_BOOKIE_GROUPS, "");
+                                        managedLedgerConfig.
+                                                setBookKeeperEnsemblePlacementPolicyProperties(properties);
+                                    }
+                                }
+                            } catch (Exception e) {
+                                log.warn("Error getting bookie isolation info from zk", e);

Review comment:
       How to fail?




-- 
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@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org