[fix](ipv6)fix can not resolve host and port (#25254)

for ipv6,address should be [ip]:port instead of ip:port
This commit is contained in:
zhangdong
2023-10-17 15:46:45 +08:00
committed by GitHub
parent 31a5e072e7
commit f38f5f50eb
27 changed files with 121 additions and 55 deletions

View File

@ -38,6 +38,7 @@ import org.apache.doris.catalog.TabletInvertedIndex;
import org.apache.doris.common.Config;
import org.apache.doris.common.DdlException;
import org.apache.doris.common.UserException;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.ha.FrontendNodeType;
import org.apache.doris.system.Backend;
import org.apache.doris.system.SystemInfoService;
@ -210,8 +211,7 @@ public class SystemHandler extends AlterHandler {
hostInfo.getPort());
if (backend == null) {
throw new DdlException("Backend does not exist["
+ hostInfo.getHost()
+ ":" + hostInfo.getPort() + "]");
+ NetUtils.getHostPortInAccessibleFormat(hostInfo.getHost(), hostInfo.getPort()) + "]");
}
if (backend.isDecommissioned()) {
// already under decommission, ignore it
@ -239,7 +239,7 @@ public class SystemHandler extends AlterHandler {
hostInfo.getPort());
if (backend == null) {
throw new DdlException("Backend does not exist["
+ hostInfo.getHost() + ":" + hostInfo.getPort() + "]");
+ NetUtils.getHostPortInAccessibleFormat(hostInfo.getHost(), hostInfo.getPort()) + "]");
}
if (!backend.isDecommissioned()) {

View File

@ -21,6 +21,7 @@ import org.apache.doris.catalog.Env;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.system.Backend;
@ -39,7 +40,8 @@ public class AdminCancelRebalanceDiskStmt extends DdlStmt {
ImmutableMap<Long, Backend> backendsInfo = Env.getCurrentSystemInfo().getIdToBackend();
Map<String, Long> backendsID = new HashMap<String, Long>();
for (Backend backend : backendsInfo.values()) {
backendsID.put(backend.getHost() + ":" + backend.getHeartbeatPort(), backend.getId());
backendsID.put(NetUtils.getHostPortInAccessibleFormat(backend.getHost(), backend.getHeartbeatPort()),
backend.getId());
}
if (backends == null) {
for (Backend backend : backendsInfo.values()) {

View File

@ -21,6 +21,7 @@ import org.apache.doris.catalog.Env;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.system.Backend;
@ -39,7 +40,9 @@ public class AdminCleanTrashStmt extends DdlStmt {
ImmutableMap<Long, Backend> backendsInfo = Env.getCurrentSystemInfo().getIdToBackend();
Map<String, Long> backendsID = new HashMap<String, Long>();
for (Backend backend : backendsInfo.values()) {
backendsID.put(backend.getHost() + ":" + backend.getHeartbeatPort(), backend.getId());
backendsID.put(
NetUtils.getHostPortInAccessibleFormat(backend.getHost(), backend.getHeartbeatPort()),
backend.getId());
}
if (backends == null) {
for (Backend backend : backendsInfo.values()) {

View File

@ -21,6 +21,7 @@ import org.apache.doris.catalog.Env;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.system.Backend;
@ -40,7 +41,9 @@ public class AdminRebalanceDiskStmt extends DdlStmt {
ImmutableMap<Long, Backend> backendsInfo = Env.getCurrentSystemInfo().getIdToBackend();
Map<String, Long> backendsID = new HashMap<String, Long>();
for (Backend backend : backendsInfo.values()) {
backendsID.put(backend.getHost() + ":" + backend.getHeartbeatPort(), backend.getId());
backendsID.put(
NetUtils.getHostPortInAccessibleFormat(backend.getHost(), backend.getHeartbeatPort()),
backend.getId());
}
if (backends == null) {
this.backends.addAll(backendsInfo.values());

View File

@ -24,6 +24,7 @@ import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.proc.TrashProcNode;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.ShowResultSetMetaData;
@ -38,7 +39,7 @@ public class ShowTrashDiskStmt extends ShowStmt {
public ShowTrashDiskStmt(String backendQuery) {
ImmutableMap<Long, Backend> backendsInfo = Env.getCurrentSystemInfo().getIdToBackend();
for (Backend backend : backendsInfo.values()) {
String backendStr = String.valueOf(backend.getHost()) + ":" + String.valueOf(backend.getHeartbeatPort());
String backendStr = NetUtils.getHostPortInAccessibleFormat(backend.getHost(), backend.getHeartbeatPort());
if (backendQuery.equals(backendStr)) {
this.backend = backend;
break;

View File

@ -27,6 +27,7 @@ import org.apache.doris.common.io.Writable;
import org.apache.doris.common.proc.BaseProcResult;
import org.apache.doris.common.proc.ProcNodeInterface;
import org.apache.doris.common.proc.ProcResult;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.common.util.TimeUtils;
import com.google.common.collect.ArrayListMultimap;
@ -219,7 +220,8 @@ public class BrokerMgr {
List<FsBroker> addressList = brokerAddrsMap.get(pair.first);
for (FsBroker addr : addressList) {
if (addr.port == pair.second) {
throw new DdlException("Broker(" + pair.first + ":" + pair.second
throw new DdlException("Broker(" + NetUtils
.getHostPortInAccessibleFormat(pair.first, pair.second)
+ ") has already in brokers.");
}
}
@ -274,7 +276,8 @@ public class BrokerMgr {
}
}
if (!found) {
throw new DdlException("Broker(" + pair.first + ":" + pair.second + ") has not in brokers.");
throw new DdlException("Broker(" + NetUtils
.getHostPortInAccessibleFormat(pair.first, pair.second) + ") has not in brokers.");
}
}
Env.getCurrentEnv().getEditLog().logDropBroker(new ModifyBrokerInfo(name, droppedAddressList));

View File

@ -2741,10 +2741,12 @@ public class Env {
try {
Frontend fe = checkFeExist(host, port);
if (fe == null) {
throw new DdlException("frontend does not exist[" + host + ":" + port + "]");
throw new DdlException("frontend does not exist[" + NetUtils
.getHostPortInAccessibleFormat(host, port) + "]");
}
if (fe.getRole() != role) {
throw new DdlException(role.toString() + " does not exist[" + host + ":" + port + "]");
throw new DdlException(role.toString() + " does not exist[" + NetUtils
.getHostPortInAccessibleFormat(host, port) + "]");
}
frontends.remove(fe.getNodeName());
removedFrontends.add(fe.getNodeName());

View File

@ -19,6 +19,7 @@ package org.apache.doris.catalog;
import org.apache.doris.common.io.Text;
import org.apache.doris.common.io.Writable;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.persist.gson.GsonUtils;
import org.apache.doris.system.BrokerHbResponse;
import org.apache.doris.system.HeartbeatResponse.HbStatus;
@ -123,7 +124,7 @@ public class FsBroker implements Writable, Comparable<FsBroker> {
@Override
public String toString() {
return host + ":" + port;
return NetUtils.getHostPortInAccessibleFormat(host, port);
}
public static FsBroker readIn(DataInput in) throws IOException {

View File

@ -22,6 +22,7 @@ import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.ClientPool;
import org.apache.doris.common.Pair;
import org.apache.doris.common.util.DebugUtil;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.system.Backend;
import org.apache.doris.thrift.BackendService;
import org.apache.doris.thrift.TNetworkAddress;
@ -94,7 +95,7 @@ public class TrashProcDir implements ProcDirInterface {
List<String> backendInfo = new ArrayList<>();
backendInfo.add(String.valueOf(backend.getId()));
backendInfo.add(backend.getHost() + ":" + backend.getHeartbeatPort());
backendInfo.add(NetUtils.getHostPortInAccessibleFormat(backend.getHost(), backend.getHeartbeatPort()));
if (trashUsedCapacityB != null) {
Pair<Double, String> trashUsedCapacity = DebugUtil.getByteUint(trashUsedCapacityB);
backendInfo.add(DebugUtil.DECIMAL_FORMAT_SCALE_3.format(trashUsedCapacity.first) + " "

View File

@ -100,7 +100,8 @@ public class BrokerReader {
}
public TBrokerFD open(String path) throws IOException {
String clientId = FrontendOptions.getLocalHostAddress() + ":" + Config.rpc_port;
String clientId = NetUtils
.getHostPortInAccessibleFormat(FrontendOptions.getLocalHostAddress(), Config.rpc_port);
TBrokerOpenReaderRequest tOpenReaderRequest = new TBrokerOpenReaderRequest(
TBrokerVersion.VERSION_ONE, path, 0, clientId, brokerDesc.getProperties());
TBrokerOpenReaderResponse tOpenReaderResponse = null;

View File

@ -217,7 +217,8 @@ public class BrokerUtil {
long fileSize = fileStatuses.get(0).getSize();
// open reader
String clientId = FrontendOptions.getLocalHostAddress() + ":" + Config.rpc_port;
String clientId = NetUtils
.getHostPortInAccessibleFormat(FrontendOptions.getLocalHostAddress(), Config.rpc_port);
TBrokerOpenReaderRequest tOpenReaderRequest = new TBrokerOpenReaderRequest(
TBrokerVersion.VERSION_ONE, path, 0, clientId, brokerDesc.getProperties());
TBrokerOpenReaderResponse tOpenReaderResponse = null;
@ -501,7 +502,8 @@ public class BrokerUtil {
address = BrokerUtil.getAddress(brokerDesc);
client = BrokerUtil.borrowClient(address);
try {
String clientId = FrontendOptions.getLocalHostAddress() + ":" + Config.rpc_port;
String clientId = NetUtils
.getHostPortInAccessibleFormat(FrontendOptions.getLocalHostAddress(), Config.rpc_port);
TBrokerOpenWriterRequest tOpenWriterRequest = new TBrokerOpenWriterRequest(
TBrokerVersion.VERSION_ONE, brokerFilePath, TBrokerOpenMode.APPEND,
clientId, brokerDesc.getProperties());

View File

@ -20,6 +20,7 @@ package org.apache.doris.deploy.impl;
import org.apache.doris.catalog.Env;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.Pair;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.common.util.Util;
import org.apache.doris.deploy.DeployManager;
import org.apache.doris.system.SystemInfoService;
@ -215,7 +216,8 @@ public class AmbariDeployManager extends DeployManager {
for (String hostname : hostnames) {
Pair<String, Integer> hostPort = null;
try {
hostPort = SystemInfoService.validateHostAndPort(hostname + ":" + port);
hostPort = SystemInfoService.validateHostAndPort(NetUtils
.getHostPortInAccessibleFormat(hostname, port));
} catch (AnalysisException e) {
LOG.warn("Invalid host port format: {}:{}", hostname, port, e);
continue;

View File

@ -20,6 +20,7 @@ package org.apache.doris.fs.operations;
import org.apache.doris.backup.Status;
import org.apache.doris.common.Config;
import org.apache.doris.common.util.BrokerUtil;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.service.FrontendOptions;
import org.apache.doris.thrift.TBrokerCloseReaderRequest;
import org.apache.doris.thrift.TBrokerCloseWriterRequest;
@ -53,7 +54,8 @@ public class BrokerFileOperations implements FileOperations {
}
public static String clientId() {
return FrontendOptions.getLocalHostAddress() + ":" + Config.edit_log_port;
return NetUtils
.getHostPortInAccessibleFormat(FrontendOptions.getLocalHostAddress(), Config.edit_log_port);
}
@Override

View File

@ -23,6 +23,7 @@ import org.apache.doris.catalog.Env;
import org.apache.doris.cluster.ClusterNamespace;
import org.apache.doris.common.AuthenticationException;
import org.apache.doris.common.Config;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.httpv2.HttpAuthManager;
import org.apache.doris.httpv2.HttpAuthManager.SessionValue;
import org.apache.doris.httpv2.exception.UnauthorizedException;
@ -299,9 +300,11 @@ public class BaseController {
protected String getCurrentFrontendURL() {
if (Config.enable_https) {
// this could be the result of redirection.
return "https://" + FrontendOptions.getLocalHostAddress() + ":" + Config.https_port;
return "https://" + NetUtils
.getHostPortInAccessibleFormat(FrontendOptions.getLocalHostAddress(), Config.https_port);
} else {
return "http://" + FrontendOptions.getLocalHostAddress() + ":" + Config.http_port;
return "http://" + NetUtils
.getHostPortInAccessibleFormat(FrontendOptions.getLocalHostAddress(), Config.http_port);
}
}
}

View File

@ -21,6 +21,7 @@ import org.apache.doris.analysis.UserIdentity;
import org.apache.doris.catalog.Env;
import org.apache.doris.cluster.ClusterNamespace;
import org.apache.doris.common.Config;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.httpv2.controller.BaseController;
import org.apache.doris.httpv2.entity.ResponseEntityBuilder;
import org.apache.doris.httpv2.exception.UnauthorizedException;
@ -200,7 +201,8 @@ public class RestBaseController extends BaseController {
String uri = request.getRequestURI();
String query = request.getQueryString();
query = query == null ? "" : query;
String newUrl = "https://" + serverName + ":" + Config.https_port + uri + "?" + query;
String newUrl = "https://" + NetUtils.getHostPortInAccessibleFormat(serverName, Config.https_port) + uri + "?"
+ query;
LOG.info("redirect to new url: {}", newUrl);
RedirectView redirectView = new RedirectView(newUrl);
redirectView.setStatusCode(HttpStatus.TEMPORARY_REDIRECT);

View File

@ -28,6 +28,7 @@ import org.apache.doris.catalog.Table;
import org.apache.doris.catalog.TableIf;
import org.apache.doris.common.DorisHttpException;
import org.apache.doris.common.MetaNotFoundException;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.httpv2.entity.ResponseEntityBuilder;
import org.apache.doris.httpv2.rest.manager.HttpUtils;
import org.apache.doris.mysql.privilege.PrivPredicate;
@ -287,7 +288,8 @@ public class TableQueryPlanAction extends RestBaseController {
TPaloScanRange scanRange = scanRangeLocations.scan_range.palo_scan_range;
Node tabletRouting = new Node(Long.parseLong(scanRange.version), 0 /* schema hash is not used */);
for (TNetworkAddress address : scanRange.hosts) {
tabletRouting.addRouting(address.hostname + ":" + address.port);
tabletRouting.addRouting(NetUtils
.getHostPortInAccessibleFormat(address.hostname, address.port));
}
result.put(String.valueOf(scanRange.tablet_id), tabletRouting);
}

View File

@ -19,6 +19,7 @@ package org.apache.doris.httpv2.rest.manager;
import org.apache.doris.catalog.Env;
import org.apache.doris.common.Config;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.httpv2.entity.ResponseEntityBuilder;
import org.apache.doris.httpv2.rest.RestBaseController;
import org.apache.doris.mysql.privilege.PrivPredicate;
@ -63,10 +64,13 @@ public class ClusterAction extends RestBaseController {
.map(Frontend::getHost)
.collect(Collectors.toList());
result.put("mysql", frontends.stream().map(ip -> ip + ":" + Config.query_port).collect(Collectors.toList()));
result.put("http", frontends.stream().map(ip -> ip + ":" + Config.http_port).collect(Collectors.toList()));
result.put("mysql", frontends.stream().map(ip -> NetUtils
.getHostPortInAccessibleFormat(ip, Config.query_port)).collect(Collectors.toList()));
result.put("http", frontends.stream().map(ip -> NetUtils
.getHostPortInAccessibleFormat(ip, Config.http_port)).collect(Collectors.toList()));
result.put("arrow flight sql server", frontends.stream().map(
ip -> ip + ":" + Config.arrow_flight_sql_port).collect(Collectors.toList()));
ip -> NetUtils.getHostPortInAccessibleFormat(ip, Config.arrow_flight_sql_port))
.collect(Collectors.toList()));
return ResponseEntityBuilder.ok(result);
}
}

View File

@ -25,6 +25,7 @@ import org.apache.doris.common.Pair;
import org.apache.doris.common.ThreadPoolManager;
import org.apache.doris.common.proc.ProcResult;
import org.apache.doris.common.proc.ProcService;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.common.util.PropertyAnalyzer;
import org.apache.doris.ha.FrontendNodeType;
import org.apache.doris.httpv2.entity.ResponseEntityBuilder;
@ -190,7 +191,8 @@ public class NodeAction extends RestBaseController {
List<Long> beIds = Env.getCurrentSystemInfo().getAllBackendIds(true);
if (!beIds.isEmpty()) {
Backend be = Env.getCurrentSystemInfo().getBackend(beIds.get(0));
String url = "http://" + be.getHost() + ":" + be.getHttpPort() + "/api/show_config";
String url = "http://" + NetUtils.getHostPortInAccessibleFormat(be.getHost(), be.getHttpPort())
+ "/api/show_config";
String questResult = HttpUtils.doGet(url, null);
List<List<String>> configs = GsonUtils.GSON.fromJson(questResult, new TypeToken<List<List<String>>>() {
}.getType());
@ -227,14 +229,15 @@ public class NodeAction extends RestBaseController {
}
private static List<String> getFeList() {
return Env.getCurrentEnv().getFrontends(null).stream().map(fe -> fe.getHost() + ":" + Config.http_port)
return Env.getCurrentEnv().getFrontends(null).stream()
.map(fe -> NetUtils.getHostPortInAccessibleFormat(fe.getHost(), Config.http_port))
.collect(Collectors.toList());
}
private static List<String> getBeList() {
return Env.getCurrentSystemInfo().getAllBackendIds(false).stream().map(beId -> {
Backend be = Env.getCurrentSystemInfo().getBackend(beId);
return be.getHost() + ":" + be.getHttpPort();
return NetUtils.getHostPortInAccessibleFormat(be.getHost(), be.getHttpPort());
}).collect(Collectors.toList());
}
@ -357,8 +360,9 @@ public class NodeAction extends RestBaseController {
configInfoTotal.add(Lists.newArrayList());
Pair<String, Integer> hostPort = hostPorts.get(i);
configRequestDoneSignal.addMark(hostPort.first + ":" + hostPort.second, -1);
String url = "http://" + hostPort.first + ":" + hostPort.second + questPath;
String address = NetUtils.getHostPortInAccessibleFormat(hostPort.first, hostPort.second);
configRequestDoneSignal.addMark(address, -1);
String url = "http://" + address + questPath;
httpExecutor.submit(
new HttpConfigInfoTask(url, hostPort, authorization, nodeType, confNames, configRequestDoneSignal,
configInfoTotal.get(i)));
@ -433,7 +437,8 @@ public class NodeAction extends RestBaseController {
addConfig(conf);
}
}
configRequestDoneSignal.markedCountDown(hostPort.first + ":" + hostPort.second, -1);
configRequestDoneSignal.markedCountDown(NetUtils
.getHostPortInAccessibleFormat(hostPort.first, hostPort.second), -1);
} catch (Exception e) {
LOG.warn("get config from {}:{} failed.", hostPort.first, hostPort.second, e);
configRequestDoneSignal.countDown();
@ -441,7 +446,8 @@ public class NodeAction extends RestBaseController {
}
private void addConfig(List<String> conf) {
conf.add(1, hostPort.first + ":" + hostPort.second);
conf.add(1, NetUtils
.getHostPortInAccessibleFormat(hostPort.first, hostPort.second));
conf.add(2, nodeType);
config.add(conf);
}
@ -518,7 +524,8 @@ public class NodeAction extends RestBaseController {
List<Map<String, String>> failedTotal) {
for (Map.Entry<String, String> entry : configs.entrySet()) {
Map<String, String> failed = Maps.newHashMap();
addFailedConfig(entry.getKey(), entry.getValue(), hostPort.first + ":" + hostPort.second, err, failed);
addFailedConfig(entry.getKey(), entry.getValue(), NetUtils
.getHostPortInAccessibleFormat(hostPort.first, hostPort.second), err, failed);
failedTotal.add(failed);
}
}
@ -534,7 +541,8 @@ public class NodeAction extends RestBaseController {
for (SetConfigAction.ErrConfig errConfig : setConfigEntity.getErrConfigs()) {
Map<String, String> failed = Maps.newHashMap();
addFailedConfig(errConfig.getConfigName(), errConfig.getConfigValue(),
hostPort.first + ":" + hostPort.second, errConfig.getErrInfo(), failed);
NetUtils.getHostPortInAccessibleFormat(hostPort.first, hostPort.second), errConfig.getErrInfo(),
failed);
failedTotal.add(failed);
}
}
@ -800,7 +808,8 @@ public class NodeAction extends RestBaseController {
}
private String concatNodeConfig(String host, Integer port, String configName, String configValue) {
return host + ":" + port + ":" + configName + ":" + configValue;
return NetUtils
.getHostPortInAccessibleFormat(host, port) + ":" + configName + ":" + configValue;
}
private Map<String, String> parseNodeConfig(String nodeConfig) {
@ -841,13 +850,15 @@ public class NodeAction extends RestBaseController {
JsonObject jsonObject = JsonParser.parseString(response).getAsJsonObject();
String status = jsonObject.get("status").getAsString();
if (!status.equals("OK")) {
addFailedConfig(configName, configValue, hostPort.first + ":" + hostPort.second,
addFailedConfig(configName, configValue, NetUtils
.getHostPortInAccessibleFormat(hostPort.first, hostPort.second),
jsonObject.get("msg").getAsString(), failed);
}
beSetConfigDoneSignal.markedCountDown(
concatNodeConfig(hostPort.first, hostPort.second, configName, configValue), -1);
} catch (Exception e) {
LOG.warn("set be:{} config:{} failed.", hostPort.first + ":" + hostPort.second,
LOG.warn("set be:{} config:{} failed.", NetUtils
.getHostPortInAccessibleFormat(hostPort.first, hostPort.second),
configName + "=" + configValue, e);
beSetConfigDoneSignal.countDown();
}

View File

@ -26,6 +26,7 @@ import org.apache.doris.common.proc.CurrentQueryStatementsProcNode;
import org.apache.doris.common.proc.ProcResult;
import org.apache.doris.common.profile.ProfileTreeNode;
import org.apache.doris.common.profile.ProfileTreePrinter;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.common.util.ProfileManager;
import org.apache.doris.common.util.ProfileManager.ProfileElement;
import org.apache.doris.httpv2.entity.ResponseEntityBuilder;
@ -177,7 +178,8 @@ public class QueryProfileAction extends RestBaseController {
// add node information
for (List<String> query : queries) {
query.add(1, Env.getCurrentEnv().getSelfNode().getHost() + ":" + Config.http_port);
query.add(1, NetUtils.getHostPortInAccessibleFormat(Env.getCurrentEnv().getSelfNode().getHost(),
Config.http_port));
}
if (!Strings.isNullOrEmpty(search)) {

View File

@ -20,6 +20,7 @@ package org.apache.doris.journal.bdbje;
import org.apache.doris.catalog.Env;
import org.apache.doris.common.io.DataOutputBuffer;
import org.apache.doris.common.io.Writable;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.common.util.Util;
import org.apache.doris.journal.Journal;
import org.apache.doris.journal.JournalCursor;
@ -87,7 +88,7 @@ public class BDBJEJournal implements Journal { // CHECKSTYLE IGNORE THIS LINE: B
// so that we do not need to update bdbje when the IP changes.
// WARNING:However, it is necessary to ensure that the hostname of the node
// can be resolved and accessed by other nodes.
selfNodeHostPort = selfNode.getHost() + ":" + selfNode.getPort();
selfNodeHostPort = NetUtils.getHostPortInAccessibleFormat(selfNode.getHost(), selfNode.getPort());
}
/*
@ -327,7 +328,7 @@ public class BDBJEJournal implements Journal { // CHECKSTYLE IGNORE THIS LINE: B
bdbEnvironment = new BDBEnvironment();
HostInfo helperNode = Env.getServingEnv().getHelperNode();
String helperHostPort = helperNode.getHost() + ":" + helperNode.getPort();
String helperHostPort = NetUtils.getHostPortInAccessibleFormat(helperNode.getHost(), helperNode.getPort());
try {
bdbEnvironment.setup(dbEnv, selfNodeName, selfNodeHostPort, helperHostPort,
Env.getServingEnv().isElectable());
@ -411,7 +412,8 @@ public class BDBJEJournal implements Journal { // CHECKSTYLE IGNORE THIS LINE: B
bdbEnvironment.close();
bdbEnvironment.setup(new File(environmentPath), selfNodeName, selfNodeHostPort,
helperNode.getHost() + ":" + helperNode.getPort(), Env.getServingEnv().isElectable());
NetUtils.getHostPortInAccessibleFormat(helperNode.getHost(), helperNode.getPort()),
Env.getServingEnv().isElectable());
}
@Override

View File

@ -21,6 +21,7 @@ import org.apache.doris.catalog.Env;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.LdapConfig;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.common.util.SymmetricEncryption;
import org.apache.doris.persist.LdapInfo;
@ -63,7 +64,8 @@ public class LdapClient {
private void setLdapTemplateNoPool(String ldapPassword) {
LdapContextSource contextSource = new LdapContextSource();
String url = "ldap://" + LdapConfig.ldap_host + ":" + LdapConfig.ldap_port;
String url = "ldap://" + NetUtils
.getHostPortInAccessibleFormat(LdapConfig.ldap_host, LdapConfig.ldap_port);
contextSource.setUrl(url);
contextSource.setUserDn(LdapConfig.ldap_admin_name);
@ -74,7 +76,8 @@ public class LdapClient {
private void setLdapTemplatePool(String ldapPassword) {
LdapContextSource contextSource = new LdapContextSource();
String url = "ldap://" + LdapConfig.ldap_host + ":" + LdapConfig.ldap_port;
String url = "ldap://" + NetUtils
.getHostPortInAccessibleFormat(LdapConfig.ldap_host, LdapConfig.ldap_port);
contextSource.setUrl(url);
contextSource.setUserDn(LdapConfig.ldap_admin_name);

View File

@ -43,6 +43,7 @@ import org.apache.doris.common.Config;
import org.apache.doris.common.MetaNotFoundException;
import org.apache.doris.common.Pair;
import org.apache.doris.common.util.Daemon;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.common.util.TimeUtils;
import org.apache.doris.cooldown.CooldownConf;
import org.apache.doris.metric.GaugeMetric;
@ -143,7 +144,8 @@ public class ReportHandler extends Daemon {
if (backend == null) {
tStatus.setStatusCode(TStatusCode.INTERNAL_ERROR);
List<String> errorMsgs = Lists.newArrayList();
errorMsgs.add("backend[" + host + ":" + bePort + "] does not exist.");
errorMsgs.add("backend[" + NetUtils
.getHostPortInAccessibleFormat(host, bePort) + "] does not exist.");
tStatus.setErrorMsgs(errorMsgs);
return result;
}

View File

@ -24,6 +24,7 @@ import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.TabletInvertedIndex;
import org.apache.doris.common.Config;
import org.apache.doris.common.ThreadPoolManager;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.load.EtlJobType;
import org.apache.doris.load.loadv2.JobState;
import org.apache.doris.load.loadv2.LoadManager;
@ -619,7 +620,8 @@ public final class MetricRepo {
return (long) invertedIndex.getTabletNumByBackendId(beId);
}
};
tabletNum.addLabel(new MetricLabel("backend", be.getHost() + ":" + be.getHeartbeatPort()));
tabletNum.addLabel(new MetricLabel("backend",
NetUtils.getHostPortInAccessibleFormat(be.getHost(), be.getHeartbeatPort())));
DORIS_METRIC_REGISTER.addMetrics(tabletNum);
// max compaction score of tablets on each backends
@ -633,7 +635,8 @@ public final class MetricRepo {
return be.getTabletMaxCompactionScore();
}
};
tabletMaxCompactionScore.addLabel(new MetricLabel("backend", be.getHost() + ":" + be.getHeartbeatPort()));
tabletMaxCompactionScore.addLabel(new MetricLabel("backend",
NetUtils.getHostPortInAccessibleFormat(be.getHost(), be.getHeartbeatPort())));
DORIS_METRIC_REGISTER.addMetrics(tabletMaxCompactionScore);
} // end for backends

View File

@ -17,6 +17,7 @@
package org.apache.doris.mysql;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.ConnectProcessor;
@ -99,7 +100,8 @@ public class MysqlChannel {
this.conn = connection;
if (connection.getPeerAddress() instanceof InetSocketAddress) {
InetSocketAddress address = (InetSocketAddress) connection.getPeerAddress();
remoteHostPortString = address.getHostString() + ":" + address.getPort();
remoteHostPortString = NetUtils
.getHostPortInAccessibleFormat(address.getHostString(), address.getPort());
remoteIp = address.getAddress().getHostAddress();
} else {
// Reach here, what's it?

View File

@ -172,6 +172,7 @@ import org.apache.doris.common.profile.ProfileTreePrinter;
import org.apache.doris.common.util.ListComparator;
import org.apache.doris.common.util.LogBuilder;
import org.apache.doris.common.util.LogKey;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.common.util.OrderByPair;
import org.apache.doris.common.util.PrintableMap;
import org.apache.doris.common.util.ProfileManager;
@ -1393,10 +1394,11 @@ public class ShowExecutor {
SystemInfoService infoService = Env.getCurrentSystemInfo();
Backend be = infoService.getBackendWithHttpPort(host, port);
if (be == null) {
throw new AnalysisException(host + ":" + port + " is not a valid backend");
throw new AnalysisException(NetUtils.getHostPortInAccessibleFormat(host, port) + " is not a valid backend");
}
if (!be.isAlive()) {
throw new AnalysisException("Backend " + host + ":" + port + " is not alive");
throw new AnalysisException(
"Backend " + NetUtils.getHostPortInAccessibleFormat(host, port) + " is not alive");
}
if (!url.getPath().equals("/api/_load_error_log")) {

View File

@ -231,7 +231,8 @@ public class SystemInfoService {
for (HostInfo hostInfo : hostInfos) {
// check is already exist
if (getBackendWithHeartbeatPort(hostInfo.getHost(), hostInfo.getPort()) == null) {
String backendIdentifier = hostInfo.getHost() + ":" + hostInfo.getPort();
String backendIdentifier = NetUtils
.getHostPortInAccessibleFormat(hostInfo.getHost(), hostInfo.getPort());
throw new DdlException("backend does not exists[" + backendIdentifier + "]");
}
}
@ -253,8 +254,8 @@ public class SystemInfoService {
public void dropBackend(String host, int heartbeatPort) throws DdlException {
Backend droppedBackend = getBackendWithHeartbeatPort(host, heartbeatPort);
if (droppedBackend == null) {
throw new DdlException("backend does not exists[" + host
+ ":" + heartbeatPort + "]");
throw new DdlException("backend does not exists[" + NetUtils
.getHostPortInAccessibleFormat(host, heartbeatPort) + "]");
}
// update idToBackend
Map<Long, Backend> copiedBackends = Maps.newHashMap(idToBackendRef);
@ -881,7 +882,8 @@ public class SystemInfoService {
public void modifyBackendHost(ModifyBackendHostNameClause clause) throws UserException {
Backend be = getBackendWithHeartbeatPort(clause.getHost(), clause.getPort());
if (be == null) {
throw new DdlException("backend does not exists[" + clause.getHost() + ":" + clause.getPort() + "]");
throw new DdlException("backend does not exists[" + NetUtils
.getHostPortInAccessibleFormat(clause.getHost(), clause.getPort()) + "]");
}
if (be.getHost().equals(clause.getNewHost())) {
// no need to modify
@ -898,7 +900,8 @@ public class SystemInfoService {
Backend be = getBackendWithHeartbeatPort(hostInfo.getHost(), hostInfo.getPort());
if (be == null) {
throw new DdlException(
"backend does not exists[" + hostInfo.getHost() + ":" + hostInfo.getPort() + "]");
"backend does not exists[" + NetUtils
.getHostPortInAccessibleFormat(hostInfo.getHost(), hostInfo.getPort()) + "]");
}
backends.add(be);
}

View File

@ -39,6 +39,7 @@ import org.apache.doris.common.UserException;
import org.apache.doris.common.util.BrokerUtil;
import org.apache.doris.common.util.FileFormatConstants;
import org.apache.doris.common.util.FileFormatUtils;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.common.util.Util;
import org.apache.doris.planner.PlanNodeId;
import org.apache.doris.planner.ScanNode;
@ -360,7 +361,8 @@ public abstract class ExternalFileTableValuedFunction extends TableValuedFunctio
errMsg = result.getStatus().getErrorMsgsList().get(0);
} else {
errMsg = "fetchTableStructureAsync failed. backend address: "
+ address.getHostname() + ":" + address.getPort();
+ NetUtils
.getHostPortInAccessibleFormat(address.getHostname(), address.getPort());
}
throw new AnalysisException(errMsg);
}