Skip to content

Commit 9a6708d

Browse files
committed
added splittingBundles map to optimize
1 parent 287b79f commit 9a6708d

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

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

+19-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 Map<String, 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 HashMap<>();
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,15 @@ 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+
String bundle = etr.getKey();
93+
final String bundleRange = LoadManagerShared.getBundleRangeFromBundleName(bundle);
94+
splittingBundles.put(bundle, bundleRange);
95+
}
96+
}
97+
8698
Map<String, NamespaceBundleStats> bundleStatsMap = pulsar.getBrokerService().getBundleStats();
8799
NamespaceBundleFactory namespaceBundleFactory =
88100
pulsar.getNamespaceService().getNamespaceBundleFactory();
@@ -185,15 +197,15 @@ public Set<SplitDecision> findBundlesToSplit(LoadManagerContext context, PulsarS
185197

186198
var ranges = bundleRange.split("_");
187199
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])) {
200+
for (var etr : splittingBundles.entrySet()) {
201+
var splittingBundle = etr.getKey();
202+
if (splittingBundle.startsWith(namespace)) {
203+
var splittingBundleRange = etr.getValue();
204+
if (splittingBundleRange.startsWith(ranges[0])
205+
|| splittingBundleRange.endsWith(ranges[1])) {
194206
if (debug) {
195207
log.info(String.format(CANNOT_SPLIT_BUNDLE_MSG
196-
+ " (parent) bundle:%s is in Splitting state.", bundle, eBundle));
208+
+ " (parent) bundle:%s is in Splitting state.", bundle, splittingBundle));
197209
}
198210
foundSplittingBundle = true;
199211
break;

0 commit comments

Comments
 (0)