yiguolei commented on code in PR #9172: URL: https://github.com/apache/incubator-doris/pull/9172#discussion_r861552190
########## fe/fe-core/src/main/java/org/apache/doris/system/FQDNManager.java: ########## @@ -0,0 +1,103 @@ +// 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.doris.system; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import org.apache.doris.catalog.BrokerMgr; +import org.apache.doris.catalog.Catalog; +import org.apache.doris.catalog.FsBroker; +import org.apache.doris.common.FeConstants; +import org.apache.doris.common.util.MasterDaemon; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.List; +import java.util.Map; + +public class FQDNManager extends MasterDaemon { + private static final Logger LOG = LogManager.getLogger(FQDNManager.class); + + private SystemInfoService nodeMgr; + + public FQDNManager(SystemInfoService nodeMgr) { + super("FQDN mgr", FeConstants.ip_check_interval_second * 1000L); + this.nodeMgr = nodeMgr; + } + + /** + * At each round: check if ip of be and broker has already been changed + */ + @Override + protected void runAfterCatalogReady() { + for (Backend be : nodeMgr.getIdToBackend().values()) { + if (be.getHostName() != null) { + try { + InetAddress inetAddress = InetAddress.getByName(be.getHostName()); + if (!be.getHost().equalsIgnoreCase(inetAddress.getHostAddress())) { + String ip = be.getHost(); + be.setHost(inetAddress.getHostAddress()); + Catalog.getCurrentCatalog().getEditLog().logBackendStateChange(be); + LOG.warn("ip for {} of be has been changed from {} to {}", be.getHostName(), ip, be.getHost()); + } + } catch (UnknownHostException e) { + LOG.warn("unknown host name for be, {}", be.getHostName(), e); + if (!be.isAlive()) { + String ip = be.getHost(); + be.setHost("unknown"); + Catalog.getCurrentCatalog().getEditLog().logBackendStateChange(be); + LOG.warn("ip for {} of be has been changed from {} to {}", be.getHostName(), ip, "unknown"); + } + } + } + } + + Map<String, List<FsBroker>> brokerMap = Maps.newHashMap( + Catalog.getCurrentCatalog().getBrokerMgr().getBrokerListMap()); + for (Map.Entry<String, List<FsBroker>> entry : brokerMap.entrySet()) { + for (FsBroker broker : entry.getValue()) { + if (broker.hostName != null) { + try { + InetAddress inetAddress = InetAddress.getByName(broker.hostName); + if (!broker.ip.equalsIgnoreCase(inetAddress.getHostAddress())) { Review Comment: And here. ########## fe/fe-core/src/main/java/org/apache/doris/system/FQDNManager.java: ########## @@ -0,0 +1,103 @@ +// 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.doris.system; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import org.apache.doris.catalog.BrokerMgr; +import org.apache.doris.catalog.Catalog; +import org.apache.doris.catalog.FsBroker; +import org.apache.doris.common.FeConstants; +import org.apache.doris.common.util.MasterDaemon; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.List; +import java.util.Map; + +public class FQDNManager extends MasterDaemon { + private static final Logger LOG = LogManager.getLogger(FQDNManager.class); + + private SystemInfoService nodeMgr; + + public FQDNManager(SystemInfoService nodeMgr) { + super("FQDN mgr", FeConstants.ip_check_interval_second * 1000L); + this.nodeMgr = nodeMgr; + } + + /** + * At each round: check if ip of be and broker has already been changed + */ + @Override + protected void runAfterCatalogReady() { + for (Backend be : nodeMgr.getIdToBackend().values()) { + if (be.getHostName() != null) { + try { + InetAddress inetAddress = InetAddress.getByName(be.getHostName()); + if (!be.getHost().equalsIgnoreCase(inetAddress.getHostAddress())) { + String ip = be.getHost(); + be.setHost(inetAddress.getHostAddress()); + Catalog.getCurrentCatalog().getEditLog().logBackendStateChange(be); + LOG.warn("ip for {} of be has been changed from {} to {}", be.getHostName(), ip, be.getHost()); + } + } catch (UnknownHostException e) { + LOG.warn("unknown host name for be, {}", be.getHostName(), e); + if (!be.isAlive()) { + String ip = be.getHost(); + be.setHost("unknown"); + Catalog.getCurrentCatalog().getEditLog().logBackendStateChange(be); + LOG.warn("ip for {} of be has been changed from {} to {}", be.getHostName(), ip, "unknown"); + } + } + } + } + + Map<String, List<FsBroker>> brokerMap = Maps.newHashMap( + Catalog.getCurrentCatalog().getBrokerMgr().getBrokerListMap()); + for (Map.Entry<String, List<FsBroker>> entry : brokerMap.entrySet()) { + for (FsBroker broker : entry.getValue()) { + if (broker.hostName != null) { Review Comment: using getter not access property directly. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org