This is an automated email from the ASF dual-hosted git repository.

xiangfu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 3236e40  Adding config to use let controller/broker/server to set 
hostname (#4517)
3236e40 is described below

commit 3236e40c2f8d3d603c82e706db41bf2c0c2eaf68
Author: Xiang Fu <[email protected]>
AuthorDate: Sat Aug 10 15:00:54 2019 -0700

    Adding config to use let controller/broker/server to set hostname (#4517)
    
    * Adding config to use let controller/broker/server to set hostname
    
    * address comments
---
 .../pinot/broker/broker/helix/HelixBrokerStarter.java    |  5 ++++-
 .../org/apache/pinot/common/utils/CommonConstants.java   |  1 +
 .../org/apache/pinot/controller/ControllerStarter.java   | 16 ++++++++++++++++
 .../pinot/server/starter/helix/HelixServerStarter.java   |  6 +++++-
 4 files changed, 26 insertions(+), 2 deletions(-)

diff --git 
a/pinot-broker/src/main/java/org/apache/pinot/broker/broker/helix/HelixBrokerStarter.java
 
b/pinot-broker/src/main/java/org/apache/pinot/broker/broker/helix/HelixBrokerStarter.java
index 57beed3..0bb6d0a 100644
--- 
a/pinot-broker/src/main/java/org/apache/pinot/broker/broker/helix/HelixBrokerStarter.java
+++ 
b/pinot-broker/src/main/java/org/apache/pinot/broker/broker/helix/HelixBrokerStarter.java
@@ -52,6 +52,7 @@ import org.apache.pinot.common.config.TagNameUtils;
 import org.apache.pinot.common.metadata.ZKMetadataProvider;
 import org.apache.pinot.common.metrics.BrokerMeter;
 import org.apache.pinot.common.metrics.BrokerMetrics;
+import org.apache.pinot.common.utils.CommonConstants;
 import org.apache.pinot.common.utils.CommonConstants.Broker;
 import org.apache.pinot.common.utils.CommonConstants.Helix;
 import org.apache.pinot.common.utils.NetUtil;
@@ -107,7 +108,9 @@ public class HelixBrokerStarter {
     _zkServers = zkServer.replaceAll("\\s+", "");
 
     if (brokerHost == null) {
-      brokerHost = NetUtil.getHostAddress();
+      brokerHost =
+        
_brokerConf.getBoolean(CommonConstants.Helix.SET_INSTANCE_ID_TO_HOSTNAME_KEY, 
false) ? NetUtil
+            .getHostnameOrAddress() : NetUtil.getHostAddress();
     }
     _brokerId = _brokerConf.getString(Helix.Instance.INSTANCE_ID_KEY,
         Helix.PREFIX_OF_BROKER_INSTANCE + brokerHost + "_" + _brokerConf
diff --git 
a/pinot-common/src/main/java/org/apache/pinot/common/utils/CommonConstants.java 
b/pinot-common/src/main/java/org/apache/pinot/common/utils/CommonConstants.java
index 386621b..663557e 100644
--- 
a/pinot-common/src/main/java/org/apache/pinot/common/utils/CommonConstants.java
+++ 
b/pinot-common/src/main/java/org/apache/pinot/common/utils/CommonConstants.java
@@ -102,6 +102,7 @@ public class CommonConstants {
         return ServerType.REALTIME;
       }
     }
+    public static final String SET_INSTANCE_ID_TO_HOSTNAME_KEY = 
"pinot.set.instance.id.to.hostname";
 
     public static final String KEY_OF_SERVER_NETTY_PORT = 
"pinot.server.netty.port";
     public static final int DEFAULT_SERVER_NETTY_PORT = 8098;
diff --git 
a/pinot-controller/src/main/java/org/apache/pinot/controller/ControllerStarter.java
 
b/pinot-controller/src/main/java/org/apache/pinot/controller/ControllerStarter.java
index 310748b..7c04510 100644
--- 
a/pinot-controller/src/main/java/org/apache/pinot/controller/ControllerStarter.java
+++ 
b/pinot-controller/src/main/java/org/apache/pinot/controller/ControllerStarter.java
@@ -52,6 +52,7 @@ import org.apache.pinot.common.metrics.MetricsHelper;
 import org.apache.pinot.common.metrics.ValidationMetrics;
 import org.apache.pinot.common.segment.fetcher.SegmentFetcherFactory;
 import org.apache.pinot.common.utils.CommonConstants;
+import org.apache.pinot.common.utils.NetUtil;
 import org.apache.pinot.common.utils.ServiceStatus;
 import org.apache.pinot.controller.api.ControllerAdminApiApplication;
 import org.apache.pinot.controller.api.access.AccessControlFactory;
@@ -124,6 +125,7 @@ public class ControllerStarter {
 
   public ControllerStarter(ControllerConf conf) {
     _config = conf;
+    inferHostnameIfNeeded(_config);
     setupHelixSystemProperties();
 
     _controllerMode = conf.getControllerMode();
@@ -152,6 +154,20 @@ public class ControllerStarter {
     }
   }
 
+  private void inferHostnameIfNeeded(ControllerConf config) {
+    if (config.getControllerHost() == null) {
+      if 
(config.getBoolean(CommonConstants.Helix.SET_INSTANCE_ID_TO_HOSTNAME_KEY, 
false)) {
+        final String inferredHostname = NetUtil.getHostnameOrAddress();
+        if (inferredHostname != null) {
+          config.setControllerHost(inferredHostname);
+        } else {
+          throw new RuntimeException(
+              "Failed to infer controller hostname, please set controller 
instanceId explicitly in config file.");
+        }
+      }
+    }
+  }
+
   private void setupHelixSystemProperties() {
     // NOTE: Helix will disconnect the manager and disable the instance if it 
detects flapping (too frequent disconnect
     // from ZooKeeper). Setting flapping time window to a small value can 
avoid this from happening. Helix ignores the
diff --git 
a/pinot-server/src/main/java/org/apache/pinot/server/starter/helix/HelixServerStarter.java
 
b/pinot-server/src/main/java/org/apache/pinot/server/starter/helix/HelixServerStarter.java
index e69f275..cf27baa 100644
--- 
a/pinot-server/src/main/java/org/apache/pinot/server/starter/helix/HelixServerStarter.java
+++ 
b/pinot-server/src/main/java/org/apache/pinot/server/starter/helix/HelixServerStarter.java
@@ -52,6 +52,7 @@ import org.apache.pinot.common.config.TagNameUtils;
 import org.apache.pinot.common.metadata.ZKMetadataProvider;
 import org.apache.pinot.common.metrics.ServerMeter;
 import org.apache.pinot.common.metrics.ServerMetrics;
+import org.apache.pinot.common.utils.CommonConstants;
 import org.apache.pinot.common.utils.NetUtil;
 import org.apache.pinot.common.utils.ServiceStatus;
 import org.apache.pinot.common.utils.ServiceStatus.Status;
@@ -141,7 +142,10 @@ public class HelixServerStarter {
     if (_serverConf.containsKey(CONFIG_OF_INSTANCE_ID)) {
       _instanceId = _serverConf.getString(CONFIG_OF_INSTANCE_ID);
     } else {
-      String host = _serverConf.getString(KEY_OF_SERVER_NETTY_HOST, 
NetUtil.getHostAddress());
+      String host = _serverConf.getString(KEY_OF_SERVER_NETTY_HOST,
+          
_serverConf.getBoolean(CommonConstants.Helix.SET_INSTANCE_ID_TO_HOSTNAME_KEY, 
false) ? NetUtil
+              .getHostnameOrAddress() : NetUtil.getHostAddress());
+
       int port = _serverConf.getInt(KEY_OF_SERVER_NETTY_PORT, 
DEFAULT_SERVER_NETTY_PORT);
       _instanceId = PREFIX_OF_SERVER_INSTANCE + host + "_" + port;
       _serverConf.addProperty(CONFIG_OF_INSTANCE_ID, _instanceId);


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to