Skip to content

Commit

Permalink
SystemPropertiesHandler use Files::move instead of File::renameTo (#1…
Browse files Browse the repository at this point in the history
…2770)

* Files.move

* ?

* ?

* ?
  • Loading branch information
liyuheng55555 authored Jun 19, 2024
1 parent 36dd489 commit 4e50e84
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@ public void checkSystemConfig() throws ConfigurationException, IOException {
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,11 @@ protected void doAddNode() {
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -158,12 +159,14 @@ private void replaceFormalFile() throws IOException {
"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);
}
}

Expand Down

0 comments on commit 4e50e84

Please sign in to comment.