This is an automated email from the ASF dual-hosted git repository.

xingfudeshi pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/incubator-seata.git


The following commit(s) were added to refs/heads/2.x by this push:
     new 0495f837ee optimize:Optimize minor issues in the naming-server (#7310)
0495f837ee is described below

commit 0495f837ee342f806a44266a1bdfe298f18be853
Author: xingfudeshi <xingfude...@gmail.com>
AuthorDate: Sun Apr 27 10:18:57 2025 +0800

    optimize:Optimize minor issues in the naming-server (#7310)
---
 changes/en-us/2.x.md                               |  3 +-
 changes/zh-cn/2.x.md                               |  3 +-
 .../java/org/apache/seata/console/Application.java | 37 ----------------------
 .../namingserver/NamingserverApplication.java      | 14 +++++++-
 .../seata/namingserver/manager/NamingManager.java  | 16 +++++-----
 .../file/store/FileVGroupMappingStoreManager.java  | 21 ++++--------
 6 files changed, 31 insertions(+), 63 deletions(-)

diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index 9506f6d1cd..b6532ae7c9 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -31,10 +31,10 @@ Add changes here for all PR submitted to the 2.x branch.
 
 ### optimize:
 
+- [[#7310](https://github.com/seata/seata/pull/7310)] Optimize minor issues in 
the naming-server
 - [[#7282](https://github.com/apache/incubator-seata/pull/7282)] optimize 
unexpected NullPointerException in lookup method in FileRegistryServiceImpl 
class
 
 
-
 ### security:
 
 - [[#PR_NO](https://github.com/seata/seata/pull/PR_NO)] upgrade XXX
@@ -61,6 +61,7 @@ Thanks to these contributors for their code commits. Please 
report an unintended
 
 - [slievrly](https://github.com/slievrly)
 - [Monilnarang](https://github.com/Monilnarang)
+- [xingfudeshi](https://github.com/xingfudeshi)
 - [wjwang00](https://github.com/wjwang00)
 - [YongGoose](https://github.com/YongGoose)
 
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index 6c36018d20..d6d6cc2b4a 100644
--- a/changes/zh-cn/2.x.md
+++ b/changes/zh-cn/2.x.md
@@ -31,7 +31,7 @@
 ### optimize:
 
 - [[#7282](https://github.com/apache/incubator-seata/pull/7282)] 
优化FileRegistryServiceImpl类lookup的NullPointerException问题
-
+- [[#7310](https://github.com/seata/seata/pull/7310)] 优化naming-server中的一些小问题
 
 
 ### security:
@@ -60,6 +60,7 @@
 
 - [slievrly](https://github.com/slievrly)
 - [Monilnarang](https://github.com/Monilnarang)
+- [xingfudeshi](https://github.com/xingfudeshi)
 - [wjwang00](https://github.com/wjwang00)
 - [YongGoose](https://github.com/YongGoose)
 
diff --git a/console/src/main/java/org/apache/seata/console/Application.java 
b/console/src/main/java/org/apache/seata/console/Application.java
deleted file mode 100644
index dbd8cc1e1b..0000000000
--- a/console/src/main/java/org/apache/seata/console/Application.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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.seata.console;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-
-/**
- * The type Application.
- *
- */
-@SpringBootApplication(scanBasePackages = {"org.apache.seata.console"})
-public class Application {
-
-    /**
-     * The entry point of application.
-     *
-     * @param args the input arguments
-     */
-    public static void main(String[] args) {
-        SpringApplication.run(Application.class, args);
-    }
-}
diff --git 
a/namingserver/src/main/java/org/apache/seata/namingserver/NamingserverApplication.java
 
b/namingserver/src/main/java/org/apache/seata/namingserver/NamingserverApplication.java
index 9b3f501d4e..2edb28509f 100644
--- 
a/namingserver/src/main/java/org/apache/seata/namingserver/NamingserverApplication.java
+++ 
b/namingserver/src/main/java/org/apache/seata/namingserver/NamingserverApplication.java
@@ -16,14 +16,26 @@
  */
 package org.apache.seata.namingserver;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 
 @SpringBootApplication(scanBasePackages = {"org.apache.seata"})
-public class NamingserverApplication {
+public class NamingserverApplication implements ApplicationRunner {
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(NamingserverApplication.class);
+    @Value("${server.port}")
+    private int port;
 
     public static void main(String[] args) {
         SpringApplication.run(NamingserverApplication.class, args);
     }
 
+    @Override
+    public void run(ApplicationArguments args) throws Exception {
+        LOGGER.info("Seata Console can be accessed at http://localhost:{}";, 
port);
+    }
 }
diff --git 
a/namingserver/src/main/java/org/apache/seata/namingserver/manager/NamingManager.java
 
b/namingserver/src/main/java/org/apache/seata/namingserver/manager/NamingManager.java
index 0474b9bcc4..a2f3328254 100644
--- 
a/namingserver/src/main/java/org/apache/seata/namingserver/manager/NamingManager.java
+++ 
b/namingserver/src/main/java/org/apache/seata/namingserver/manager/NamingManager.java
@@ -116,7 +116,7 @@ public class NamingManager {
             try {
                 instanceHeartBeatCheck();
             } catch (Exception e) {
-                LOGGER.error("Heart Beat Check Exception", e);
+                LOGGER.error("Heart Beat Check Exception:{}", e.getMessage(), 
e);
             }
         }, heartbeatCheckTimePeriod, heartbeatCheckTimePeriod, 
TimeUnit.MILLISECONDS);
     }
@@ -132,7 +132,7 @@ public class NamingManager {
                 clusterVOHashMap.put(clusterName, 
ClusterVO.convertFromClusterData(clusterData));
             }
         } else {
-            LOGGER.warn("no cluster in namespace:" + namespace);
+            LOGGER.warn("no cluster in namespace:{}", namespace);
         }
 
         vGroupMap.asMap().forEach((vGroup, namespaceMap) -> {
@@ -154,7 +154,7 @@ public class NamingManager {
         List<Node> nodeList = getInstances(namespace, clusterName);
         if (nodeList == null || nodeList.size() == 0) {
             LOGGER.error("no instance in cluster {}", clusterName);
-            return new Result<>("301", "no instance in cluster" + clusterName);
+            return new Result<>("301", "no instance in cluster:" + 
clusterName);
         } else {
             Node node =
                 nodeList.stream().filter(n -> n.getRole() == 
ClusterRole.LEADER || n.getRole() == ClusterRole.MEMBER)
@@ -176,7 +176,7 @@ public class NamingManager {
                 }
                 LOGGER.info("namespace: {} add vGroup: {} in new cluster: {} 
successfully!", namespace, vGroup, clusterName);
             } catch (IOException e) {
-                LOGGER.warn("add vGroup in new cluster failed");
+                LOGGER.error("add vGroup in new cluster failed:{}", 
e.getMessage(), e);
                 return new Result<>("500", "add vGroup in new cluster failed");
             }
         }
@@ -203,7 +203,7 @@ public class NamingManager {
                 LOGGER.info("namespace: {} remove vGroup: {} in new cluster: 
{} successfully!", namespace, vGroup,
                     clusterName);
             } catch (IOException e) {
-                LOGGER.warn("handle removing vGroup in old cluster failed");
+                LOGGER.error("handle removing vGroup in old cluster 
failed:{}", e.getMessage(), e);
                 return new Result<>("500",
                     "handle removing vGroup " + vGroup + " in old cluster " + 
clusterName + " failed");
             }
@@ -225,7 +225,7 @@ public class NamingManager {
                 return needNotify;
             }
         } catch (Exception e) {
-            LOGGER.error("change vGroup mapping failed:{}", vGroup, e);
+            LOGGER.error("change vGroup mapping failed,vGroup:{},error:{}", 
vGroup, e.getMessage(), e);
         }
         return false;
     }
@@ -272,7 +272,7 @@ public class NamingManager {
                 new InetSocketAddress(node.getTransaction().getHost(), 
node.getTransaction().getPort()),
                 System.currentTimeMillis());
         } catch (Exception e) {
-            LOGGER.error("Instance registered failed!", e);
+            LOGGER.error("Instance registered failed:{}", e.getMessage(), e);
             return false;
         }
         return true;
@@ -299,7 +299,7 @@ public class NamingManager {
                 }
             }
         } catch (Exception e) {
-            LOGGER.error("Instance unregistered failed!", e);
+            LOGGER.error("Instance unregistered failed:{}", e.getMessage(), e);
             return false;
         }
         return true;
diff --git 
a/server/src/main/java/org/apache/seata/server/storage/file/store/FileVGroupMappingStoreManager.java
 
b/server/src/main/java/org/apache/seata/server/storage/file/store/FileVGroupMappingStoreManager.java
index 3a6f161c2c..9edfdd48a6 100644
--- 
a/server/src/main/java/org/apache/seata/server/storage/file/store/FileVGroupMappingStoreManager.java
+++ 
b/server/src/main/java/org/apache/seata/server/storage/file/store/FileVGroupMappingStoreManager.java
@@ -26,6 +26,7 @@ import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import org.apache.seata.common.loader.LoadLevel;
+import org.apache.seata.common.util.StringUtils;
 import org.apache.seata.config.Configuration;
 import org.apache.seata.config.ConfigurationFactory;
 import org.apache.seata.core.store.MappingDO;
@@ -109,29 +110,19 @@ public class FileVGroupMappingStoreManager implements 
VGroupMappingStoreManager
         try {
             File fileToLoad = new File(storePath);
             if (!fileToLoad.exists()) {
-                try {
-                    // create new file to record vgroup mapping relationship
-                    boolean fileCreated = fileToLoad.createNewFile();
-                    if (fileCreated) {
-                        LOGGER.info("New vgroup file created at path: " + 
storePath);
-                    } else {
-                        LOGGER.warn("Failed to create a new vgroup file at 
path: " + storePath);
-                    }
-                } catch (IOException e) {
-                    LOGGER.error("Error while creating a new file: " + 
e.getMessage());
-                }
+                // create new file to record vgroup mapping relationship
+                FileUtils.writeStringToFile(fileToLoad, StringUtils.EMPTY, 
StandardCharsets.UTF_8);
             }
 
-            String fileContent = FileUtils.readFileToString(fileToLoad, 
"UTF-8");
+            String fileContent = FileUtils.readFileToString(fileToLoad, 
StandardCharsets.UTF_8);
 
             if (!fileContent.isEmpty()) {
                 vGroupMapping = objectMapper.readValue(fileContent, new 
TypeReference<HashMap<String, Object>>() {
                 });
             }
 
-
         } catch (Exception e) {
-            LOGGER.error("mapping relationship load failed! " + e);
+            throw new RuntimeException("mapping relationship load failed",e);
         }
         return vGroupMapping;
     }
@@ -143,7 +134,7 @@ public class FileVGroupMappingStoreManager implements 
VGroupMappingStoreManager
             FileUtils.writeStringToFile(new File(storePath), jsonMapping, 
StandardCharsets.UTF_8);
             return true;
         } catch (IOException e) {
-            LOGGER.error("mapping relationship saved failed! ", e);
+            LOGGER.error("mapping relationship saved failed:{}", 
e.getMessage(), e);
             return false;
         }
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org
For additional commands, e-mail: notifications-h...@seata.apache.org

Reply via email to