eolivelli commented on a change in pull request #8961:
URL: https://github.com/apache/pulsar/pull/8961#discussion_r550052157
##########
File path:
pulsar-zookeeper-utils/src/main/java/org/apache/pulsar/zookeeper/ZkIsolatedBookieEnsemblePlacementPolicy.java
##########
@@ -156,34 +177,79 @@ private ZooKeeperCache getAndSetZkCache(Configuration
conf) {
bookieToReplace, excludeBookies);
}
- private Set<BookieId> getBlacklistedBookies(int ensembleSize) {
- Set<BookieId> blacklistedBookies = new HashSet<BookieId>();
+ private Optional<EnsemblePlacementPolicyConfig>
getEnsemblePlacementPolicyConfig(
+ Map<String, byte[]> customMetadata) {
+
+ byte[] ensemblePlacementPolicyConfigData = customMetadata.get(
+ EnsemblePlacementPolicyConfig.ENSEMBLE_PLACEMENT_POLICY_CONFIG);
+ if (ensemblePlacementPolicyConfigData != null) {
+ try {
+ return
Optional.ofNullable(EnsemblePlacementPolicyConfig.decode(ensemblePlacementPolicyConfigData));
+ } catch (JsonUtil.ParseJsonException e) {
+ LOG.error("Failed to parse the ensemble placement policy
config from the custom metadata", e);
+ return Optional.empty();
+ }
+ }
+ return Optional.empty();
+ }
+
+ private Map<String, List<String>> getDefaultIsolationGroups() {
Review comment:
you can pass the instance variable to the method, this way it is clearer
that the method has not side effects
##########
File path:
pulsar-zookeeper-utils/src/main/java/org/apache/pulsar/zookeeper/ZkIsolatedBookieEnsemblePlacementPolicy.java
##########
@@ -156,34 +177,79 @@ private ZooKeeperCache getAndSetZkCache(Configuration
conf) {
bookieToReplace, excludeBookies);
}
- private Set<BookieId> getBlacklistedBookies(int ensembleSize) {
- Set<BookieId> blacklistedBookies = new HashSet<BookieId>();
+ private Optional<EnsemblePlacementPolicyConfig>
getEnsemblePlacementPolicyConfig(
+ Map<String, byte[]> customMetadata) {
+
+ byte[] ensemblePlacementPolicyConfigData = customMetadata.get(
+ EnsemblePlacementPolicyConfig.ENSEMBLE_PLACEMENT_POLICY_CONFIG);
+ if (ensemblePlacementPolicyConfigData != null) {
+ try {
+ return
Optional.ofNullable(EnsemblePlacementPolicyConfig.decode(ensemblePlacementPolicyConfigData));
+ } catch (JsonUtil.ParseJsonException e) {
+ LOG.error("Failed to parse the ensemble placement policy
config from the custom metadata", e);
+ return Optional.empty();
+ }
+ }
+ return Optional.empty();
+ }
+
+ private Map<String, List<String>> getDefaultIsolationGroups() {
+ Map<String, List<String>> isolationGroup = new HashMap<>();
+ isolationGroup.put(ISOLATION_BOOKIE_GROUPS, primaryIsolationGroups);
+ isolationGroup.put(SECONDARY_ISOLATION_BOOKIE_GROUPS,
secondaryIsolationGroups);
+ return isolationGroup;
+ }
+
+ private Map<String, List<String>>
getIsolationGroup(EnsemblePlacementPolicyConfig ensemblePlacementPolicyConfig) {
+ Map<String, List<String>> groups = new HashMap<>();
+ String className =
ZkIsolatedBookieEnsemblePlacementPolicy.class.getName();
+ if
(ensemblePlacementPolicyConfig.getPolicyClass().getName().equals(className)) {
+ Map<String, Object> properties =
ensemblePlacementPolicyConfig.getProperties();
+ String primaryIsolationGroupString =
castToString(properties.getOrDefault(ISOLATION_BOOKIE_GROUPS, ""));
+ String secondaryIsolationGroupString =
castToString(properties.getOrDefault(SECONDARY_ISOLATION_BOOKIE_GROUPS, ""));
+ if (!primaryIsolationGroupString.isEmpty()) {
+ List<String> primaryGroup =
Arrays.asList(primaryIsolationGroupString.split(","));
+ groups.put(ISOLATION_BOOKIE_GROUPS, primaryGroup);
+ }
+ if (!secondaryIsolationGroupString.isEmpty()) {
+ List<String> secondaryGroup =
Arrays.asList(secondaryIsolationGroupString.split(","));
+ groups.put(SECONDARY_ISOLATION_BOOKIE_GROUPS, secondaryGroup);
+ }
+ }
+ return groups;
+ }
+
+ private Set<BookieId> getBlacklistedBookiesWithIsolationGroups(int
ensembleSize,
Review comment:
you can pass the instance variable to the method, this way it is clearer
that the method has not side effects
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]