@@ -319,19 +319,15 @@ public void registerBootstrapNamespaces() throws PulsarServerException {
319
319
* @throws Exception
320
320
*/
321
321
public boolean registerNamespace (NamespaceName nsname , boolean ensureOwned ) throws PulsarServerException {
322
-
323
- String myUrl = pulsar .getSafeBrokerServiceUrl ();
324
-
325
322
try {
326
- String otherUrl = null ;
327
323
NamespaceBundle nsFullBundle = null ;
328
324
329
325
// all pre-registered namespace is assumed to have bundles disabled
330
326
nsFullBundle = bundleFactory .getFullBundle (nsname );
331
327
// v2 namespace will always use full bundle object
332
- otherUrl = ownershipCache .tryAcquiringOwnership (nsFullBundle ).get (). getNativeUrl ();
333
-
334
- if ( myUrl .equals (otherUrl )) {
328
+ NamespaceEphemeralData otherData = ownershipCache .tryAcquiringOwnership (nsFullBundle ).get ();
329
+ if ( StringUtils . equals ( pulsar . getBrokerServiceUrl (), otherData . getNativeUrl ())
330
+ || StringUtils .equals (pulsar . getBrokerServiceUrlTls (), otherData . getNativeUrlTls () )) {
335
331
if (nsFullBundle != null ) {
336
332
// preload heartbeat namespace
337
333
pulsar .loadNamespaceTopics (nsFullBundle );
@@ -340,7 +336,9 @@ public boolean registerNamespace(NamespaceName nsname, boolean ensureOwned) thro
340
336
}
341
337
342
338
String msg = String .format ("namespace already owned by other broker : ns=%s expected=%s actual=%s" ,
343
- nsname , myUrl , otherUrl );
339
+ nsname ,
340
+ StringUtils .defaultString (pulsar .getBrokerServiceUrl (), pulsar .getBrokerServiceUrlTls ()),
341
+ StringUtils .defaultString (otherData .getNativeUrl (), otherData .getNativeUrlTls ()));
344
342
345
343
// ignore if not be owned for now
346
344
if (!ensureOwned ) {
@@ -415,9 +413,10 @@ private CompletableFuture<Optional<LookupResult>> findBrokerServiceUrl(
415
413
new PulsarServerException ("the broker do not have "
416
414
+ options .getAdvertisedListenerName () + " listener" ));
417
415
} else {
416
+ URI url = listener .getBrokerServiceUrl ();
418
417
URI urlTls = listener .getBrokerServiceUrlTls ();
419
418
future .complete (Optional .of (new LookupResult (nsData .get (),
420
- listener . getBrokerServiceUrl () .toString (),
419
+ url == null ? null : url .toString (),
421
420
urlTls == null ? null : urlTls .toString ())));
422
421
}
423
422
return ;
@@ -535,9 +534,11 @@ private void searchForCandidateBroker(NamespaceBundle bundle,
535
534
+ options .getAdvertisedListenerName () + " listener" ));
536
535
return ;
537
536
} else {
537
+ URI url = listener .getBrokerServiceUrl ();
538
538
URI urlTls = listener .getBrokerServiceUrlTls ();
539
539
lookupFuture .complete (Optional .of (
540
- new LookupResult (ownerInfo , listener .getBrokerServiceUrl ().toString (),
540
+ new LookupResult (ownerInfo ,
541
+ url == null ? null : url .toString (),
541
542
urlTls == null ? null : urlTls .toString ())));
542
543
return ;
543
544
}
@@ -596,9 +597,10 @@ protected CompletableFuture<LookupResult> createLookupResult(String candidateBro
596
597
new PulsarServerException (
597
598
"the broker do not have " + advertisedListenerName + " listener" ));
598
599
} else {
600
+ URI url = listener .getBrokerServiceUrl ();
599
601
URI urlTls = listener .getBrokerServiceUrlTls ();
600
602
lookupFuture .complete (new LookupResult (lookupData .getWebServiceUrl (),
601
- lookupData .getWebServiceUrlTls (), listener . getBrokerServiceUrl () .toString (),
603
+ lookupData .getWebServiceUrlTls (), url == null ? null : url .toString (),
602
604
urlTls == null ? null : urlTls .toString (), authoritativeRedirect ));
603
605
}
604
606
} else {
0 commit comments