Skip to content

Commit eef66dd

Browse files
committed
fix unload bundle metric.
1 parent c724f02 commit eef66dd

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.concurrent.Executors;
3939
import java.util.concurrent.RejectedExecutionException;
4040
import java.util.concurrent.TimeUnit;
41+
import java.util.concurrent.atomic.AtomicBoolean;
4142
import java.util.concurrent.atomic.AtomicReference;
4243
import java.util.concurrent.locks.Lock;
4344
import java.util.concurrent.locks.ReentrantLock;
@@ -625,6 +626,7 @@ public synchronized void doLoadShedding() {
625626
final Multimap<String, String> bundlesToUnload = loadSheddingStrategy.findBundlesForUnloading(loadData, conf);
626627

627628
bundlesToUnload.asMap().forEach((broker, bundles) -> {
629+
AtomicBoolean unloadBundleForBroker = new AtomicBoolean(false);
628630
bundles.forEach(bundle -> {
629631
final String namespaceName = LoadManagerShared.getNamespaceNameFromBundleName(bundle);
630632
final String bundleRange = LoadManagerShared.getBundleRangeFromBundleName(bundle);
@@ -654,24 +656,24 @@ public synchronized void doLoadShedding() {
654656
pulsar.getAdminClient().namespaces()
655657
.unloadNamespaceBundle(namespaceName, bundleRange, destBroker.get());
656658
loadData.getRecentlyUnloadedBundles().put(bundle, System.currentTimeMillis());
659+
unloadBundleCount++;
660+
unloadBundleForBroker.set(true);
657661
} catch (PulsarServerException | PulsarAdminException e) {
658662
log.warn("Error when trying to perform load shedding on {} for broker {}", bundle, broker, e);
659663
}
660664
});
665+
if (unloadBundleForBroker.get()) {
666+
unloadBrokerCount++;
667+
}
661668
});
662669

663-
updateBundleUnloadingMetrics(bundlesToUnload);
670+
updateBundleUnloadingMetrics();
664671
}
665672

666673
/**
667674
* As leader broker, update bundle unloading metrics.
668-
*
669-
* @param bundlesToUnload
670675
*/
671-
private void updateBundleUnloadingMetrics(Multimap<String, String> bundlesToUnload) {
672-
unloadBrokerCount += bundlesToUnload.keySet().size();
673-
unloadBundleCount += bundlesToUnload.values().size();
674-
676+
private void updateBundleUnloadingMetrics() {
675677
List<Metrics> metrics = new ArrayList<>();
676678
Map<String, String> dimensions = new HashMap<>();
677679

0 commit comments

Comments
 (0)