This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 0e7f63f5f6 [fix](ipv6)Remove restrictions from IPv4 when add backend
(#22323)
0e7f63f5f6 is described below
commit 0e7f63f5f67587a5fc99c39cd3ec518a4b57050c
Author: zhangdong <[email protected]>
AuthorDate: Sun Jul 30 22:47:24 2023 +0800
[fix](ipv6)Remove restrictions from IPv4 when add backend (#22323)
When adding be, it is required to have only one colon, otherwise an error
will be reported. However, ipv6 has many colons
```
String[] pair = hostPort.split(":");
if (pair.length != 2) {
throw new AnalysisException("Invalid host port: " + hostPort);
}
```
---
.../org/apache/doris/common/util/NetUtils.java | 14 +++++-----
.../org/apache/doris/system/SystemInfoService.java | 5 ----
.../apache/doris/system/SystemInfoServiceTest.java | 32 ++++++++++++++++++++++
3 files changed, 39 insertions(+), 12 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/common/util/NetUtils.java
b/fe/fe-core/src/main/java/org/apache/doris/common/util/NetUtils.java
index 3470cea203..334dd11564 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/common/util/NetUtils.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/common/util/NetUtils.java
@@ -137,16 +137,16 @@ public class NetUtils {
}
public static SystemInfoService.HostInfo
resolveHostInfoFromHostPort(String hostPort) throws AnalysisException {
+ String[] pair;
if (hostPort.charAt(0) == '[') {
- String[] pair = hostPort.substring(1).split("]:");
- return new SystemInfoService.HostInfo(pair[0],
Integer.valueOf(pair[1]));
+ pair = hostPort.substring(1).split("]:");
} else {
- String[] pair = hostPort.split(":");
- if (pair.length != 2) {
- throw new AnalysisException("invalid host port: " + hostPort);
- }
- return new SystemInfoService.HostInfo(pair[0],
Integer.valueOf(pair[1]));
+ pair = hostPort.split(":");
+ }
+ if (pair.length != 2) {
+ throw new AnalysisException("invalid host port: " + hostPort);
}
+ return new SystemInfoService.HostInfo(pair[0],
Integer.valueOf(pair[1]));
}
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/system/SystemInfoService.java
b/fe/fe-core/src/main/java/org/apache/doris/system/SystemInfoService.java
index 0f4639a13f..6523f9f0f0 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/system/SystemInfoService.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/system/SystemInfoService.java
@@ -718,11 +718,6 @@ public class SystemInfoService {
throw new AnalysisException("Invalid host port: " + hostPort);
}
- String[] pair = hostPort.split(":");
- if (pair.length != 2) {
- throw new AnalysisException("Invalid host port: " + hostPort);
- }
-
HostInfo hostInfo = NetUtils.resolveHostInfoFromHostPort(hostPort);
String host = hostInfo.getHost();
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/system/SystemInfoServiceTest.java
b/fe/fe-core/src/test/java/org/apache/doris/system/SystemInfoServiceTest.java
index 172fbd5594..d207e0ce2a 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/system/SystemInfoServiceTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/system/SystemInfoServiceTest.java
@@ -20,9 +20,11 @@ package org.apache.doris.system;
import org.apache.doris.catalog.DiskInfo;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.ReplicaAllocation;
+import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.FeMetaVersion;
import org.apache.doris.meta.MetaContext;
import org.apache.doris.resource.Tag;
+import org.apache.doris.system.SystemInfoService.HostInfo;
import org.apache.doris.thrift.TStorageMedium;
import com.google.common.collect.ImmutableMap;
@@ -57,6 +59,35 @@ public class SystemInfoServiceTest {
infoService.addBackend(backend);
}
+ @Test
+ public void testGetHostAndPort() {
+ String ipv4 = "192.168.1.2:9050";
+ String ipv6 = "[fe80::5054:ff:fec9:dee0]:9050";
+ String ipv6Error = "fe80::5054:ff:fec9:dee0:9050";
+ try {
+ HostInfo hostAndPort = SystemInfoService.getHostAndPort(ipv4);
+ Assert.assertEquals("192.168.1.2", hostAndPort.getHost());
+ Assert.assertEquals(9050, hostAndPort.getPort());
+ } catch (AnalysisException e) {
+ e.printStackTrace();
+ Assert.fail();
+ }
+ try {
+ HostInfo hostAndPort = SystemInfoService.getHostAndPort(ipv6);
+ Assert.assertEquals("fe80::5054:ff:fec9:dee0",
hostAndPort.getHost());
+ Assert.assertEquals(9050, hostAndPort.getPort());
+ } catch (AnalysisException e) {
+ e.printStackTrace();
+ Assert.fail();
+ }
+ try {
+ SystemInfoService.getHostAndPort(ipv6Error);
+ Assert.fail();
+ } catch (AnalysisException e) {
+ e.printStackTrace();
+ }
+ }
+
@Test
public void testBackendHbResponseSerialization() throws IOException {
MetaContext metaContext = new MetaContext();
@@ -401,4 +432,5 @@ public class SystemInfoServiceTest {
tagMap.put(Tag.TYPE_ROLE, Tag.VALUE_COMPUTATION);
be.setTagMap(tagMap);
}
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]