-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[improve][broker] PIP-192: Support broker isolation policy #19592
Merged
Technoboy-
merged 6 commits into
apache:master
from
Demogorgon314:Demogorgon314/PIP-192-Support_Broker_isolation_policy
Mar 11, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
483e430
Support broker isolation policy
Demogorgon314 bb20928
Remove todo
Demogorgon314 6ca9b9b
Address comments
Demogorgon314 aaec1c8
Reuse LoadManagerShared
Demogorgon314 2dc33da
Merge master into current branch
Demogorgon314 cbaddfd
Change name
Demogorgon314 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
60 changes: 60 additions & 0 deletions
60
...org/apache/pulsar/broker/loadbalance/extensions/filter/BrokerIsolationPoliciesFilter.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,60 @@ | ||
/* | ||
* 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 java.util.Set; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.pulsar.broker.PulsarService; | ||
import org.apache.pulsar.broker.loadbalance.BrokerFilterException; | ||
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.IsolationPoliciesHelper; | ||
import org.apache.pulsar.broker.loadbalance.impl.SimpleResourceAllocationPolicies; | ||
import org.apache.pulsar.common.naming.ServiceUnitId; | ||
|
||
|
||
@Slf4j | ||
public class BrokerIsolationPoliciesFilter implements BrokerFilter { | ||
|
||
public static final String FILTER_NAME = "broker_isolation_policies_filter"; | ||
|
||
private IsolationPoliciesHelper isolationPoliciesHelper; | ||
|
||
@Override | ||
public String name() { | ||
return FILTER_NAME; | ||
} | ||
|
||
@Override | ||
public void initialize(PulsarService pulsar) { | ||
this.isolationPoliciesHelper = new IsolationPoliciesHelper(new SimpleResourceAllocationPolicies(pulsar)); | ||
} | ||
|
||
@Override | ||
public Map<String, BrokerLookupData> filter(Map<String, BrokerLookupData> availableBrokers, | ||
ServiceUnitId serviceUnit, | ||
LoadManagerContext context) | ||
throws BrokerFilterException { | ||
Set<String> brokerCandidateCache = | ||
isolationPoliciesHelper.applyIsolationPolicies(availableBrokers, serviceUnit); | ||
availableBrokers.keySet().retainAll(brokerCandidateCache); | ||
return availableBrokers; | ||
} | ||
} |
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
68 changes: 68 additions & 0 deletions
68
...ava/org/apache/pulsar/broker/loadbalance/extensions/policies/IsolationPoliciesHelper.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,68 @@ | ||
/* | ||
* 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 io.netty.util.concurrent.FastThreadLocal; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.pulsar.broker.loadbalance.extensions.data.BrokerLookupData; | ||
import org.apache.pulsar.broker.loadbalance.impl.LoadManagerShared; | ||
import org.apache.pulsar.broker.loadbalance.impl.SimpleResourceAllocationPolicies; | ||
import org.apache.pulsar.common.naming.ServiceUnitId; | ||
|
||
@Slf4j | ||
public class IsolationPoliciesHelper { | ||
|
||
private final SimpleResourceAllocationPolicies policies; | ||
|
||
public IsolationPoliciesHelper(SimpleResourceAllocationPolicies policies) { | ||
this.policies = policies; | ||
} | ||
|
||
private static final FastThreadLocal<Set<String>> localBrokerCandidateCache = new FastThreadLocal<>() { | ||
@Override | ||
protected Set<String> initialValue() { | ||
return new HashSet<>(); | ||
} | ||
}; | ||
|
||
public Set<String> applyIsolationPolicies(Map<String, BrokerLookupData> availableBrokers, | ||
ServiceUnitId serviceUnit) { | ||
Set<String> brokerCandidateCache = localBrokerCandidateCache.get(); | ||
brokerCandidateCache.clear(); | ||
LoadManagerShared.applyNamespacePolicies(serviceUnit, policies, brokerCandidateCache, | ||
availableBrokers.keySet(), new LoadManagerShared.BrokerTopicLoadingPredicate() { | ||
@Override | ||
public boolean isEnablePersistentTopics(String brokerUrl) { | ||
BrokerLookupData lookupData = availableBrokers.get(brokerUrl.replace("http://", "")); | ||
return lookupData != null && lookupData.persistentTopicsEnabled(); | ||
} | ||
|
||
@Override | ||
public boolean isEnableNonPersistentTopics(String brokerUrl) { | ||
BrokerLookupData lookupData = availableBrokers.get(brokerUrl.replace("http://", "")); | ||
return lookupData != null && lookupData.nonPersistentTopicsEnabled(); | ||
} | ||
}); | ||
return brokerCandidateCache; | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
.../src/main/java/org/apache/pulsar/broker/loadbalance/extensions/policies/package-info.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,19 @@ | ||
/* | ||
* 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; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is good to consider the isolation policy here in this shedding strategy. However, it might be better if we just do not automatically unload/transfer bundles that configure any isolation policy or anti-affinity group.
Reasoning: These bundles configure limited sets of brokers to transfer/unload, which is not an ideal target to move around regarding load balance. (Hopefully, not all of the top k loaded bundles comply with isolation policy) It would be better to move other bundles that don't comply with any policies. "Fix bundles that have hard limits but move other free ones."
For this reason, we could probably filter out those bundles with isolation or anti-affinity group policy in the
TopKBundles,
just like we filter out the system namespace bundles. WDYT?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it is harmful to keep this logic here. I can add those bundle filtering logic(filtering out bundles with isolation and anti-affinity-group in topk bundles) in my next PR(anti-affinity group support).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, let's keep the logic here temporarily, since your proposal will change the original behavior. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. sounds good to me.