Demogorgon314 commented on code in PR #20970:
URL: https://github.com/apache/pulsar/pull/20970#discussion_r1295569028
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/impl/ModularLoadManagerImpl.java:
##########
@@ -275,24 +277,32 @@ public void initialize(final PulsarService pulsar) {
// register listeners for domain changes
pulsar.getPulsarResources().getClusterResources().getFailureDomainResources()
.registerListener(__ -> {
- executors.execute(
+ scheduler.execute(
() ->
LoadManagerShared.refreshBrokerToFailureDomainMap(pulsar,
brokerToFailureDomainMap));
});
loadSheddingPipeline.add(createLoadSheddingStrategy());
}
+ private boolean isLeader() {
+ return pulsar.getLeaderElectionService() != null
+ && pulsar.getLeaderElectionService().isLeader();
+ }
+
public void handleDataNotification(Notification t) {
if (t.getPath().startsWith(LoadManager.LOADBALANCE_BROKERS_ROOT)) {
brokersData.listLocks(LoadManager.LOADBALANCE_BROKERS_ROOT)
.thenAccept(brokers -> {
reapDeadBrokerPreallocations(brokers);
});
+ oldFlag = true;
- try {
- executors.execute(ModularLoadManagerImpl.this::updateAll);
- } catch (RejectedExecutionException e) {
- // Executor is shutting down
+ if (isLeader()) {
+ try {
+ scheduler.submit(ModularLoadManagerImpl.this::updateAll);
Review Comment:
We need a unit test to verify this change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]