This is an automated email from the ASF dual-hosted git repository.
yashmayya pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new edf47313e7e Fix server host resolution when host is configured (#18625)
edf47313e7e is described below
commit edf47313e7e0cad96c2fb5985f11d3054ac9670a
Author: Cc <[email protected]>
AuthorDate: Mon Jun 1 11:07:46 2026 +0800
Fix server host resolution when host is configured (#18625)
Co-authored-by: wolfkill <[email protected]>
---
.../server/starter/helix/BaseServerStarter.java | 15 +++-
.../starter/helix/BaseServerStarterTest.java | 79 ++++++++++++++++++++++
2 files changed, 91 insertions(+), 3 deletions(-)
diff --git
a/pinot-server/src/main/java/org/apache/pinot/server/starter/helix/BaseServerStarter.java
b/pinot-server/src/main/java/org/apache/pinot/server/starter/helix/BaseServerStarter.java
index 4571a521167..59627f3ef25 100644
---
a/pinot-server/src/main/java/org/apache/pinot/server/starter/helix/BaseServerStarter.java
+++
b/pinot-server/src/main/java/org/apache/pinot/server/starter/helix/BaseServerStarter.java
@@ -220,9 +220,7 @@ public abstract class BaseServerStarter implements
ServiceStartable {
setupHelixSystemProperties();
_listenerConfigs = ListenerConfigUtil.buildServerAdminConfigs(_serverConf);
- _hostname = _serverConf.getProperty(Helix.KEY_OF_SERVER_NETTY_HOST,
- _serverConf.getProperty(Helix.SET_INSTANCE_ID_TO_HOSTNAME_KEY, false)
? NetUtils.getHostnameOrAddress()
- : NetUtils.getHostAddress());
+ _hostname = getServerHostname(_serverConf);
// Override multi-stage query runner hostname if not set explicitly
if
(!_serverConf.containsKey(CommonConstants.MultiStageQueryRunner.KEY_OF_QUERY_RUNNER_HOSTNAME))
{
_serverConf.setProperty(CommonConstants.MultiStageQueryRunner.KEY_OF_QUERY_RUNNER_HOSTNAME,
_hostname);
@@ -324,6 +322,17 @@ public abstract class BaseServerStarter implements
ServiceStartable {
return DefaultQueryOperatorFactoryProvider.INSTANCE;
}
+ @VisibleForTesting
+ static String getServerHostname(PinotConfiguration serverConf)
+ throws IOException {
+ String configuredHost =
serverConf.getProperty(Helix.KEY_OF_SERVER_NETTY_HOST);
+ if (configuredHost != null) {
+ return configuredHost;
+ }
+ return serverConf.getProperty(Helix.SET_INSTANCE_ID_TO_HOSTNAME_KEY,
false) ? NetUtils.getHostnameOrAddress()
+ : NetUtils.getHostAddress();
+ }
+
/**
* Invoke pinot environment provider factory's init method to register the
environment provider &
* return the instantiated environment provider.
diff --git
a/pinot-server/src/test/java/org/apache/pinot/server/starter/helix/BaseServerStarterTest.java
b/pinot-server/src/test/java/org/apache/pinot/server/starter/helix/BaseServerStarterTest.java
new file mode 100644
index 00000000000..2bc7645522b
--- /dev/null
+++
b/pinot-server/src/test/java/org/apache/pinot/server/starter/helix/BaseServerStarterTest.java
@@ -0,0 +1,79 @@
+/**
+ * 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.pinot.server.starter.helix;
+
+import org.apache.pinot.spi.env.PinotConfiguration;
+import org.apache.pinot.spi.utils.CommonConstants.Helix;
+import org.apache.pinot.spi.utils.NetUtils;
+import org.mockito.MockedStatic;
+import org.testng.annotations.Test;
+
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.never;
+import static org.testng.Assert.assertEquals;
+
+public class BaseServerStarterTest {
+ @Test
+ public void testConfiguredServerHostDoesNotResolveDefaultHost()
+ throws Exception {
+ PinotConfiguration serverConf = new PinotConfiguration();
+ serverConf.setProperty(Helix.KEY_OF_SERVER_NETTY_HOST,
"pinot-server-node1");
+
+ try (MockedStatic<NetUtils> netUtils = mockStatic(NetUtils.class)) {
+ netUtils.when(NetUtils::getHostAddress).thenThrow(new
AssertionError("Should not resolve host address"));
+ netUtils.when(NetUtils::getHostnameOrAddress).thenThrow(new
AssertionError("Should not resolve hostname"));
+
+ assertEquals(BaseServerStarter.getServerHostname(serverConf),
"pinot-server-node1");
+
+ netUtils.verify(NetUtils::getHostAddress, never());
+ netUtils.verify(NetUtils::getHostnameOrAddress, never());
+ }
+ }
+
+ @Test
+ public void testServerHostFallsBackToHostAddress()
+ throws Exception {
+ PinotConfiguration serverConf = new PinotConfiguration();
+
+ try (MockedStatic<NetUtils> netUtils = mockStatic(NetUtils.class)) {
+ netUtils.when(NetUtils::getHostAddress).thenReturn("10.0.0.1");
+
+ assertEquals(BaseServerStarter.getServerHostname(serverConf),
"10.0.0.1");
+
+ netUtils.verify(NetUtils::getHostAddress);
+ netUtils.verify(NetUtils::getHostnameOrAddress, never());
+ }
+ }
+
+ @Test
+ public void testServerHostFallsBackToHostnameWhenConfigured()
+ throws Exception {
+ PinotConfiguration serverConf = new PinotConfiguration();
+ serverConf.setProperty(Helix.SET_INSTANCE_ID_TO_HOSTNAME_KEY, true);
+
+ try (MockedStatic<NetUtils> netUtils = mockStatic(NetUtils.class)) {
+
netUtils.when(NetUtils::getHostnameOrAddress).thenReturn("pinot-server-node1");
+
+ assertEquals(BaseServerStarter.getServerHostname(serverConf),
"pinot-server-node1");
+
+ netUtils.verify(NetUtils::getHostnameOrAddress);
+ netUtils.verify(NetUtils::getHostAddress, never());
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]