-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[improve][broker] PIP-192 Supports AntiAffinityGroupPolicy (#19708)
Master Issue: #16691 ### Motivation Raising a PR to implement #16691. We need to support AntiAffinityGroupPolicy in Load Manager Extension as well. ### Modifications This PR - added AntiAffinityGroupPolicyFilter used in the broker assignment logic. - added AntiAffinityGroupPolicyHelper that is passed to TransferShedder and AntiAffinityGroupPolicyFilter - modified LoadManagerShared.filterAntiAffinityGroupOwnedBrokers and LoadManagerShared.getAntiAffinityNamespaceOwnedBrokers to accept the bundle ownership data from the Load Manager Extension. - moved ModularLoadManagerImpl.refreshBrokerToFailureDomainMap(..) to LoadManager.refreshBrokerToFailureDomainMap(..) to reuse it in ExtensibleLoadManagerImpl. - modified AntiAffinityNamespaceGroupTest to reuse the test cases in AntiAffinityNamespaceGroupExtensionTest
- Loading branch information
1 parent
9a85dea
commit 2ddfbfe
Showing
11 changed files
with
841 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...org/apache/pulsar/broker/loadbalance/extensions/filter/AntiAffinityGroupPolicyFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.broker.loadbalance.extensions.filter; | ||
|
||
import java.util.Map; | ||
import org.apache.pulsar.broker.PulsarService; | ||
import org.apache.pulsar.broker.loadbalance.extensions.LoadManagerContext; | ||
import org.apache.pulsar.broker.loadbalance.extensions.data.BrokerLookupData; | ||
import org.apache.pulsar.broker.loadbalance.extensions.policies.AntiAffinityGroupPolicyHelper; | ||
import org.apache.pulsar.common.naming.ServiceUnitId; | ||
|
||
/** | ||
* Filter by anti-affinity-group-policy. | ||
*/ | ||
public class AntiAffinityGroupPolicyFilter implements BrokerFilter { | ||
|
||
public static final String FILTER_NAME = "broker_anti_affinity_group_filter"; | ||
|
||
private final AntiAffinityGroupPolicyHelper helper; | ||
|
||
public AntiAffinityGroupPolicyFilter(AntiAffinityGroupPolicyHelper helper) { | ||
this.helper = helper; | ||
} | ||
|
||
@Override | ||
public Map<String, BrokerLookupData> filter( | ||
Map<String, BrokerLookupData> brokers, ServiceUnitId serviceUnitId, LoadManagerContext context) { | ||
helper.filter(brokers, serviceUnitId.toString()); | ||
return brokers; | ||
} | ||
|
||
|
||
@Override | ||
public String name() { | ||
return FILTER_NAME; | ||
} | ||
|
||
@Override | ||
public void initialize(PulsarService pulsar) { | ||
return; | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
...g/apache/pulsar/broker/loadbalance/extensions/policies/AntiAffinityGroupPolicyHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.broker.loadbalance.extensions.policies; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.pulsar.broker.PulsarService; | ||
import org.apache.pulsar.broker.loadbalance.extensions.channel.ServiceUnitStateChannel; | ||
import org.apache.pulsar.broker.loadbalance.extensions.data.BrokerLookupData; | ||
import org.apache.pulsar.broker.loadbalance.impl.LoadManagerShared; | ||
import org.apache.pulsar.metadata.api.MetadataStoreException; | ||
|
||
@Slf4j | ||
public class AntiAffinityGroupPolicyHelper { | ||
PulsarService pulsar; | ||
Map<String, String> brokerToFailureDomainMap; | ||
ServiceUnitStateChannel channel; | ||
|
||
public AntiAffinityGroupPolicyHelper(PulsarService pulsar, | ||
ServiceUnitStateChannel channel){ | ||
|
||
this.pulsar = pulsar; | ||
this.brokerToFailureDomainMap = new HashMap<>(); | ||
this.channel = channel; | ||
} | ||
|
||
public void filter( | ||
Map<String, BrokerLookupData> brokers, String bundle) { | ||
LoadManagerShared.filterAntiAffinityGroupOwnedBrokers(pulsar, bundle, | ||
brokers.keySet(), | ||
channel.getOwnershipEntrySet(), brokerToFailureDomainMap); | ||
} | ||
|
||
public boolean canUnload( | ||
Map<String, BrokerLookupData> brokers, | ||
String bundle, | ||
String srcBroker, | ||
Optional<String> dstBroker) { | ||
|
||
|
||
|
||
try { | ||
var antiAffinityGroupOptional = LoadManagerShared.getNamespaceAntiAffinityGroup( | ||
pulsar, LoadManagerShared.getNamespaceNameFromBundleName(bundle)); | ||
if (antiAffinityGroupOptional.isPresent()) { | ||
|
||
// copy to retain the input brokers | ||
Map<String, BrokerLookupData> candidates = new HashMap<>(brokers); | ||
|
||
filter(candidates, bundle); | ||
|
||
candidates.remove(srcBroker); | ||
|
||
// unload case | ||
if (dstBroker.isEmpty()) { | ||
return !candidates.isEmpty(); | ||
} | ||
|
||
// transfer case | ||
return candidates.containsKey(dstBroker.get()); | ||
} | ||
} catch (MetadataStoreException e) { | ||
log.error("Failed to check unload candidates. Assumes that bundle:{} cannot unload ", bundle, e); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public void listenFailureDomainUpdate() { | ||
LoadManagerShared.refreshBrokerToFailureDomainMap(pulsar, brokerToFailureDomainMap); | ||
// register listeners for domain changes | ||
pulsar.getPulsarResources().getClusterResources().getFailureDomainResources() | ||
.registerListener(__ -> { | ||
pulsar.getLoadManagerExecutor().execute(() -> | ||
LoadManagerShared.refreshBrokerToFailureDomainMap(pulsar, brokerToFailureDomainMap)); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.