You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by xi...@apache.org on 2019/08/10 07:05:29 UTC
[incubator-pinot] 01/01: Adding config to use let
controller/broker/server to set hostname
This is an automated email from the ASF dual-hosted git repository.
xiangfu pushed a commit to branch prefer_host_name_over_ip
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git
commit 9223af0c3121307b54177364f23ce8fce1c6056c
Author: Xiang Fu <fx...@gmail.com>
AuthorDate: Sat Aug 10 00:05:13 2019 -0700
Adding config to use let controller/broker/server to set hostname
---
.../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..1c6fb25 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.PREFER_HOSTNAME_IN_DEFAULT_INSTANCD_ID_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..86aa857 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 PREFER_HOSTNAME_IN_DEFAULT_INSTANCD_ID_KEY = "pinot.preferHostnameInDefaultInstanceId";
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..7c80033 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.PREFER_HOSTNAME_IN_DEFAULT_INSTANCD_ID_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..01a3007 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.PREFER_HOSTNAME_IN_DEFAULT_INSTANCD_ID_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: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org