Skip to content

Commit e3b361b

Browse files
committed
added splittingBundles set to optimize
1 parent 287b79f commit e3b361b

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/strategy/DefaultNamespaceBundleSplitStrategyImpl.java

+16-7
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ public class DefaultNamespaceBundleSplitStrategyImpl implements NamespaceBundleS
5858
private final Set<SplitDecision> decisionCache;
5959
private final Map<String, Integer> namespaceBundleCount;
6060
private final Map<String, Integer> splitConditionHitCounts;
61+
private final Set<String> splittingBundles;
6162
private final SplitCounter counter;
6263

6364
public DefaultNamespaceBundleSplitStrategyImpl(SplitCounter counter) {
6465
decisionCache = new HashSet<>();
6566
namespaceBundleCount = new HashMap<>();
6667
splitConditionHitCounts = new HashMap<>();
68+
splittingBundles = new HashSet<>();
6769
this.counter = counter;
6870

6971
}
@@ -72,6 +74,7 @@ public DefaultNamespaceBundleSplitStrategyImpl(SplitCounter counter) {
7274
public Set<SplitDecision> findBundlesToSplit(LoadManagerContext context, PulsarService pulsar) {
7375
decisionCache.clear();
7476
namespaceBundleCount.clear();
77+
splittingBundles.clear();
7578
final ServiceConfiguration conf = pulsar.getConfiguration();
7679
int maxBundleCount = conf.getLoadBalancerNamespaceMaximumBundles();
7780
long maxBundleTopics = conf.getLoadBalancerNamespaceBundleMaxTopics();
@@ -83,6 +86,13 @@ public Set<SplitDecision> findBundlesToSplit(LoadManagerContext context, PulsarS
8386
boolean debug = log.isDebugEnabled() || conf.isLoadBalancerDebugModeEnabled();
8487
var channel = ServiceUnitStateChannelImpl.get(pulsar);
8588

89+
for (var etr : channel.getOwnershipEntrySet()) {
90+
var eData = etr.getValue();
91+
if (eData.state() == ServiceUnitState.Splitting) {
92+
splittingBundles.add(etr.getKey());
93+
}
94+
}
95+
8696
Map<String, NamespaceBundleStats> bundleStatsMap = pulsar.getBrokerService().getBundleStats();
8797
NamespaceBundleFactory namespaceBundleFactory =
8898
pulsar.getNamespaceService().getNamespaceBundleFactory();
@@ -185,15 +195,14 @@ public Set<SplitDecision> findBundlesToSplit(LoadManagerContext context, PulsarS
185195

186196
var ranges = bundleRange.split("_");
187197
var foundSplittingBundle = false;
188-
for (var etr : channel.getOwnershipEntrySet()) {
189-
var eBundle = etr.getKey();
190-
var eData = etr.getValue();
191-
if (eData.state() == ServiceUnitState.Splitting && eBundle.startsWith(namespace)) {
192-
final String eRange = LoadManagerShared.getBundleRangeFromBundleName(eBundle);
193-
if (eRange.startsWith(ranges[0]) || eRange.endsWith(ranges[1])) {
198+
for (var splittingBundle : splittingBundles) {
199+
if (splittingBundle.startsWith(namespace)) {
200+
final String splittingBundleRange = LoadManagerShared.getBundleRangeFromBundleName(splittingBundle);
201+
if (splittingBundleRange.startsWith(ranges[0])
202+
|| splittingBundleRange.endsWith(ranges[1])) {
194203
if (debug) {
195204
log.info(String.format(CANNOT_SPLIT_BUNDLE_MSG
196-
+ " (parent) bundle:%s is in Splitting state.", bundle, eBundle));
205+
+ " (parent) bundle:%s is in Splitting state.", bundle, splittingBundle));
197206
}
198207
foundSplittingBundle = true;
199208
break;

0 commit comments

Comments
 (0)