Skip to content
Permalink
Browse files
fix a bug for system.properties (#5933)
  • Loading branch information
MrQuansy committed May 17, 2022
1 parent b0d5826 commit c0529f57aaca17297413d7811a0617baf821086a
Showing 2 changed files with 14 additions and 3 deletions.
@@ -107,7 +107,9 @@ private void storeConfigNode() throws IOException {
}
properties.setProperty(
CONFIG_NODE_LIST, NodeUrlUtils.convertTEndPointUrls(new ArrayList<>(onlineConfigNodes)));
properties.store(new FileOutputStream(propertiesFile), "");
try (FileOutputStream fileOutputStream = new FileOutputStream(propertiesFile)) {
properties.store(fileOutputStream, "");
}
}

public void loadConfigNodeList() {
@@ -108,8 +108,6 @@ public class IoTDBStartCheck {

private static final String DATA_NODE_ID = "data_node_id";

private static final String CONFIG_NODE_LIST = "config_node_list";

private static final String IOTDB_VERSION_STRING = "iotdb_version";

public static IoTDBStartCheck getInstance() {
@@ -390,6 +388,15 @@ private void throwException(String parameter, Object badValue) throws Configurat
parameter, String.valueOf(badValue), properties.getProperty(parameter));
}

// reload properties from system.properties
private void reloadProperties() throws IOException {
try (FileInputStream inputStream = new FileInputStream(propertiesFile);
InputStreamReader inputStreamReader =
new InputStreamReader(inputStream, TSFileConfig.STRING_CHARSET)) {
properties.load(inputStreamReader);
}
}

/** call this method to serialize DataNodeId */
public void serializeDataNodeId(int dataNodeId) throws IOException {
// create an empty tmpPropertiesFile
@@ -400,6 +407,8 @@ public void serializeDataNodeId(int dataNodeId) throws IOException {
System.exit(-1);
}

reloadProperties();

try (FileOutputStream tmpFOS = new FileOutputStream(tmpPropertiesFile.toString())) {
properties.setProperty(DATA_NODE_ID, String.valueOf(dataNodeId));
properties.store(tmpFOS, SYSTEM_PROPERTIES_STRING);

0 comments on commit c0529f5

Please sign in to comment.