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

tanxinyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 4e50e847378 SystemPropertiesHandler use Files::move instead of 
File::renameTo (#12770)
4e50e847378 is described below

commit 4e50e8473787dfc5420764bc3d121eede0ed4deb
Author: Li Yu Heng <[email protected]>
AuthorDate: Wed Jun 19 22:17:53 2024 +0800

    SystemPropertiesHandler use Files::move instead of File::renameTo (#12770)
    
    * Files.move
    
    * ?
    
    * ?
    
    * ?
---
 .../src/main/java/org/apache/iotdb/db/conf/IoTDBStartCheck.java    | 2 --
 .../src/main/java/org/apache/iotdb/db/service/DataNode.java        | 2 ++
 .../org/apache/iotdb/commons/file/SystemPropertiesHandler.java     | 7 +++++--
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBStartCheck.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBStartCheck.java
index 64cdbe20e76..a91a8d7f7fc 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBStartCheck.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBStartCheck.java
@@ -216,8 +216,6 @@ public class IoTDBStartCheck {
     properties = systemPropertiesHandler.read();
 
     if (systemPropertiesHandler.isFirstStart()) {
-      // overwrite system.properties when first start
-      generateOrOverwriteSystemPropertiesFile();
       if 
(config.getDataRegionConsensusProtocolClass().equals(ConsensusFactory.IOT_CONSENSUS)
           && config.getWalMode().equals(WALMode.DISABLE)) {
         throw new ConfigurationException(
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNode.java 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNode.java
index c057c3392e5..f6fef6846c0 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNode.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNode.java
@@ -194,9 +194,11 @@ public class DataNode implements DataNodeMBean {
       isFirstStart = prepareDataNode();
 
       if (isFirstStart) {
+        logger.info("DataNode is starting for the first time...");
         ConfigNodeInfo.getInstance()
             
.updateConfigNodeList(Collections.singletonList(config.getSeedConfigNode()));
       } else {
+        logger.info("DataNode is restarting...");
         // Load registered ConfigNodes from system.properties
         ConfigNodeInfo.getInstance().loadConfigNodeList();
       }
diff --git 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/file/SystemPropertiesHandler.java
 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/file/SystemPropertiesHandler.java
index 61bcbb49b0c..552d408f9fc 100644
--- 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/file/SystemPropertiesHandler.java
+++ 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/file/SystemPropertiesHandler.java
@@ -20,6 +20,7 @@
 package org.apache.iotdb.commons.file;
 
 import org.apache.ratis.util.AutoCloseableLock;
+import org.apache.ratis.util.FileUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -158,12 +159,14 @@ public abstract class SystemPropertiesHandler {
               "Delete formal system properties file fail: %s", 
formalFile.getAbsoluteFile());
       throw new IOException(msg);
     }
-    if (!tmpFile.renameTo(formalFile)) {
+    try {
+      FileUtils.move(tmpFile.toPath(), formalFile.toPath());
+    } catch (IOException e) {
       String msg =
           String.format(
               "Failed to replace formal system properties file, you may 
manually rename it: %s -> %s",
               tmpFile.getAbsolutePath(), formalFile.getAbsolutePath());
-      throw new IOException(msg);
+      throw new IOException(msg, e);
     }
   }
 

Reply via email to