[GitHub] [pulsar] zplinuxlover commented on a change in pull request #6903: PIP-61: Advertise multiple addresses

2020-05-26 Thread GitBox


zplinuxlover commented on a change in pull request #6903:
URL: https://github.com/apache/pulsar/pull/6903#discussion_r429967851



##
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/lookup/TopicLookupBase.java
##
@@ -156,6 +156,31 @@ protected String internalGetNamespaceBundle(TopicName 
topicName) {
  */
 public static CompletableFuture lookupTopicAsync(PulsarService 
pulsarService, TopicName topicName,
 boolean authoritative, String clientAppId, 
AuthenticationDataSource authenticationData, long requestId) {
+return lookupTopicAsync(pulsarService, topicName, authoritative, 
clientAppId, authenticationData, requestId, null);
+}
+
+/**
+ *
+ * Lookup broker-service address for a given namespace-bundle which 
contains given topic.
+ *
+ * a. Returns broker-address if namespace-bundle is already owned by any 
broker b. If current-broker receives
+ * lookup-request and if it's not a leader then current broker redirects 
request to leader by returning
+ * leader-service address. c. If current-broker is leader then it finds 
out least-loaded broker to own namespace
+ * bundle and redirects request by returning least-loaded broker. d. If 
current-broker receives request to own the
+ * namespace-bundle then it owns a bundle and returns success(connect) 
response to client.

Review comment:
   I have format the comment

##
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/PulsarService.java
##
@@ -36,11 +36,7 @@
 import java.lang.reflect.Method;
 import java.net.InetSocketAddress;
 import java.net.URI;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
+import java.util.*;

Review comment:
   resolve the problem





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [pulsar] zplinuxlover commented on a change in pull request #6903: PIP-61: Advertise multiple addresses

2020-05-19 Thread GitBox


zplinuxlover commented on a change in pull request #6903:
URL: https://github.com/apache/pulsar/pull/6903#discussion_r42175



##
File path: 
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
##
@@ -146,6 +146,14 @@
 )
 private String advertisedAddress;
 
+//
+@FieldContext(category=CATEGORY_SERVER, doc = "")

Review comment:
   I have add the configuration doc here

##
File path: 
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
##
@@ -146,6 +146,14 @@
 )
 private String advertisedAddress;
 
+//

Review comment:
   I have remove the code for this line 

##
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceEphemeralData.java
##
@@ -63,9 +81,17 @@ public void setDisabled(boolean flag) {
 this.disabled = flag;
 }
 
+@NotNull
+public Map getAdvertisedListeners() {
+if (this.advertisedListeners == null) {
+return Collections.unmodifiableMap(Collections.EMPTY_MAP);

Review comment:
   I have fix the code

##
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceService.java
##
@@ -367,7 +387,22 @@ public boolean registerNamespace(String namespace, boolean 
ensureOwned) throws P
 if (LOG.isDebugEnabled()) {
 LOG.debug("Namespace bundle {} already owned by {} ", 
bundle, nsData);
 }
-future.complete(Optional.of(new 
LookupResult(nsData.get(;
+// find the target
+if (StringUtils.isNotBlank(advertisedListenerName)) {
+AdvertisedListener listener = 
nsData.get().getAdvertisedListeners().get(advertisedListenerName);
+if (listener == null) {
+future.completeExceptionally(
+new PulsarServerException("the broker do 
not have " + advertisedListenerName + " listener"));
+return;
+} else {
+future.complete(Optional.of(new LookupResult(
+nsData.get().getHttpUrl(), 
nsData.get().getHttpUrlTls(), listener.getBrokerServiceUrl().toString(),

Review comment:
   currently we only concern pulsar protocol here, the HttpUrl and 
HttpUrlTls behavior as before

##
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/namespace/NamespaceService.java
##
@@ -447,8 +488,23 @@ private void searchForCandidateBroker(NamespaceBundle 
bundle,
 
 // Schedule the task to pre-load topics
 pulsar.loadNamespaceTopics(bundle);
-
-lookupFuture.complete(Optional.of(new 
LookupResult(ownerInfo)));
+// find the target
+if (StringUtils.isNotBlank(advertisedListenerName)) {
+AdvertisedListener listener = 
ownerInfo.getAdvertisedListeners().get(advertisedListenerName);
+if (listener == null) {
+lookupFuture.completeExceptionally(
+new PulsarServerException("the broker 
do not have " + advertisedListenerName + " listener"));
+return;
+} else {
+lookupFuture.complete(Optional.of(new 
LookupResult(
+ownerInfo.getHttpUrl(), 
ownerInfo.getHttpUrlTls(), listener.getBrokerServiceUrl().toString(),

Review comment:
   currently we only concern pulsar protocol here, the HttpUrl and 
HttpUrlTls behavior as before.

##
File path: 
pulsar-common/src/main/java/org/apache/pulsar/policies/data/loadbalancer/AdvertisedListener.java
##
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.policies.data.loadbalancer;
+
+import java.net.URI;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter