@@ -426,6 +426,8 @@ private void searchForCandidateBroker(NamespaceBundle bundle,
426
426
CompletableFuture <Optional <LookupResult >> lookupFuture , boolean authoritative ,
427
427
final String advertisedListenerName ) {
428
428
String candidateBroker = null ;
429
+ boolean authoritativeRedirect = pulsar .getLeaderElectionService ().isLeader ();
430
+
429
431
try {
430
432
// check if this is Heartbeat or SLAMonitor namespace
431
433
candidateBroker = checkHeartbeatNamespace (bundle );
@@ -438,7 +440,10 @@ private void searchForCandidateBroker(NamespaceBundle bundle,
438
440
}
439
441
440
442
if (candidateBroker == null ) {
441
- if (!this .loadManager .get ().isCentralized ()
443
+ if (authoritative ) {
444
+ // leader broker already assigned the current broker as owner
445
+ candidateBroker = pulsar .getSafeWebServiceAddress ();
446
+ } else if (!this .loadManager .get ().isCentralized ()
442
447
|| pulsar .getLeaderElectionService ().isLeader ()
443
448
444
449
// If leader is not active, fallback to pick the least loaded from current broker loadmanager
@@ -450,14 +455,10 @@ private void searchForCandidateBroker(NamespaceBundle bundle,
450
455
return ;
451
456
}
452
457
candidateBroker = availableBroker .get ();
458
+ authoritativeRedirect = true ;
453
459
} else {
454
- if (authoritative ) {
455
- // leader broker already assigned the current broker as owner
456
- candidateBroker = pulsar .getSafeWebServiceAddress ();
457
- } else {
458
- // forward to leader broker to make assignment
459
- candidateBroker = pulsar .getLeaderElectionService ().getCurrentLeader ().getServiceUrl ();
460
- }
460
+ // forward to leader broker to make assignment
461
+ candidateBroker = pulsar .getLeaderElectionService ().getCurrentLeader ().getServiceUrl ();
461
462
}
462
463
}
463
464
} catch (Exception e ) {
@@ -519,7 +520,7 @@ private void searchForCandidateBroker(NamespaceBundle bundle,
519
520
}
520
521
521
522
// Now setting the redirect url
522
- createLookupResult (candidateBroker )
523
+ createLookupResult (candidateBroker , authoritativeRedirect )
523
524
.thenAccept (lookupResult -> lookupFuture .complete (Optional .of (lookupResult )))
524
525
.exceptionally (ex -> {
525
526
lookupFuture .completeExceptionally (ex );
@@ -533,7 +534,8 @@ private void searchForCandidateBroker(NamespaceBundle bundle,
533
534
}
534
535
}
535
536
536
- protected CompletableFuture <LookupResult > createLookupResult (String candidateBroker ) throws Exception {
537
+ protected CompletableFuture <LookupResult > createLookupResult (String candidateBroker , boolean authoritativeRedirect )
538
+ throws Exception {
537
539
538
540
CompletableFuture <LookupResult > lookupFuture = new CompletableFuture <>();
539
541
try {
@@ -546,7 +548,7 @@ protected CompletableFuture<LookupResult> createLookupResult(String candidateBro
546
548
ServiceLookupData lookupData = reportData .get ();
547
549
lookupFuture .complete (new LookupResult (lookupData .getWebServiceUrl (),
548
550
lookupData .getWebServiceUrlTls (), lookupData .getPulsarServiceUrl (),
549
- lookupData .getPulsarServiceUrlTls ()));
551
+ lookupData .getPulsarServiceUrlTls (), authoritativeRedirect ));
550
552
} else {
551
553
lookupFuture .completeExceptionally (new KeeperException .NoNodeException (path ));
552
554
}
0 commit comments