morningman commented on code in PR #9172:
URL: https://github.com/apache/doris/pull/9172#discussion_r1032897749


##########
fe/fe-core/src/main/java/org/apache/doris/system/SystemInfoService.java:
##########
@@ -901,7 +915,8 @@ public void clear() {
         this.idToReportVersionRef = null;
     }
 
-    public static Pair<String, Integer> validateHostAndPort(String hostPort) 
throws AnalysisException {
+    public static Triple<String, String, Integer> getIpHostAndPort(String 
hostPort, boolean strictCheck)

Review Comment:
   why not name `strictCheck` to `isFqdnMode`?



##########
fe/fe-core/src/main/java/org/apache/doris/system/FQDNManager.java:
##########
@@ -0,0 +1,73 @@
+// 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 org.apache.doris.catalog.Env;
+import org.apache.doris.common.ClientPool;
+import org.apache.doris.common.FeConstants;
+import org.apache.doris.common.util.MasterDaemon;
+import org.apache.doris.thrift.TNetworkAddress;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+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 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();
+                        if (!ip.equalsIgnoreCase("unknown")) {
+                            ClientPool.backendPool.clearPool(new 
TNetworkAddress(ip, be.getBePort()));

Review Comment:
   I think we should change BE'ip and write edit log before clearing the client 
pool.



##########
fe/fe-core/src/main/java/org/apache/doris/system/FQDNManager.java:
##########
@@ -0,0 +1,73 @@
+// 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 org.apache.doris.catalog.Env;
+import org.apache.doris.common.ClientPool;
+import org.apache.doris.common.FeConstants;
+import org.apache.doris.common.util.MasterDaemon;
+import org.apache.doris.thrift.TNetworkAddress;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+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 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();
+                        if (!ip.equalsIgnoreCase("unknown")) {
+                            ClientPool.backendPool.clearPool(new 
TNetworkAddress(ip, be.getBePort()));

Review Comment:
   And maybe we should extract a method called: `backend.onIPChanged()`.
   So that we can support `alter backend modify ip` later.



##########
fe/fe-core/src/main/java/org/apache/doris/system/FQDNManager.java:
##########
@@ -0,0 +1,73 @@
+// 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 org.apache.doris.catalog.Env;
+import org.apache.doris.common.ClientPool;
+import org.apache.doris.common.FeConstants;
+import org.apache.doris.common.util.MasterDaemon;
+import org.apache.doris.thrift.TNetworkAddress;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+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 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();
+                        if (!ip.equalsIgnoreCase("unknown")) {
+                            ClientPool.backendPool.clearPool(new 
TNetworkAddress(ip, be.getBePort()));
+                        }
+                        be.setHost(inetAddress.getHostAddress());
+                        
Env.getCurrentEnv().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() && 
!be.getHost().equalsIgnoreCase("unknown")) {

Review Comment:
   Why judge `!be.isAlive()`?
   Add some comment directly in code.



##########
fe/fe-core/src/main/java/org/apache/doris/system/FQDNManager.java:
##########
@@ -0,0 +1,73 @@
+// 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 org.apache.doris.catalog.Env;
+import org.apache.doris.common.ClientPool;
+import org.apache.doris.common.FeConstants;
+import org.apache.doris.common.util.MasterDaemon;
+import org.apache.doris.thrift.TNetworkAddress;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+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 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();
+                        if (!ip.equalsIgnoreCase("unknown")) {
+                            ClientPool.backendPool.clearPool(new 
TNetworkAddress(ip, be.getBePort()));
+                        }
+                        be.setHost(inetAddress.getHostAddress());
+                        
Env.getCurrentEnv().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() && 
!be.getHost().equalsIgnoreCase("unknown")) {
+                        String ip = be.getHost();
+                        ClientPool.backendPool.clearPool(new 
TNetworkAddress(ip, be.getBePort()));
+                        be.setHost("unknown");

Review Comment:
   define this `"unknown"` somewhere.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to