Skip to content

Commit 895410e

Browse files
committed
add enum
1 parent 62aa4d6 commit 895410e

3 files changed

Lines changed: 62 additions & 35 deletions

File tree

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeDescriptor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ private void loadProps() {
147147
}
148148

149149
private void loadProperties(TrimProperties properties) throws BadNodeUrlException, IOException {
150-
loadHotModifiedProps(properties);
150+
ConfigurationFileUtils.updateLastAppliedProperties(properties, false);
151+
conf.setClusterName(properties.getProperty(IoTDBConstant.CLUSTER_NAME, conf.getClusterName()));
151152

152153
conf.setInternalAddress(
153154
properties.getProperty(IoTDBConstant.CN_INTERNAL_ADDRESS, conf.getInternalAddress()));
@@ -764,8 +765,8 @@ public boolean isSeedConfigNode() {
764765
}
765766
}
766767

767-
public void loadHotModifiedProps(TrimProperties properties) {
768-
ConfigurationFileUtils.updateLastAppliedProperties(properties);
768+
public void loadHotModifiedProps(TrimProperties properties) throws IOException {
769+
ConfigurationFileUtils.updateLastAppliedProperties(properties, true);
769770
conf.setClusterName(properties.getProperty(IoTDBConstant.CLUSTER_NAME, conf.getClusterName()));
770771
}
771772

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ private void loadProps() {
255255
}
256256

257257
public void loadProperties(TrimProperties properties) throws BadNodeUrlException, IOException {
258+
ConfigurationFileUtils.updateLastAppliedProperties(properties, false);
258259
conf.setClusterName(properties.getProperty(IoTDBConstant.CLUSTER_NAME, conf.getClusterName()));
259260

260261
conf.setRpcAddress(properties.getProperty(IoTDBConstant.DN_RPC_ADDRESS, conf.getRpcAddress()));
@@ -1960,8 +1961,8 @@ private String[][] parseDataDirs(String dataDirs) {
19601961
}
19611962

19621963
public synchronized void loadHotModifiedProps(TrimProperties properties)
1963-
throws QueryProcessException {
1964-
ConfigurationFileUtils.updateLastAppliedProperties(properties);
1964+
throws QueryProcessException, IOException {
1965+
ConfigurationFileUtils.updateLastAppliedProperties(properties, true);
19651966
try {
19661967
// update data dirs
19671968
String dataDirs = properties.getProperty("dn_data_dirs", null);

iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/ConfigurationFileUtils.java

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class ConfigurationFileUtils {
5353
private static final String lockFileSuffix = ".lock";
5454
private static final long maxTimeMillsToAcquireLock = TimeUnit.SECONDS.toMillis(20);
5555
private static final long waitTimeMillsPerCheck = TimeUnit.MILLISECONDS.toMillis(100);
56-
private static Logger logger = LoggerFactory.getLogger(ConfigurationFileUtils.class);
56+
private static final Logger logger = LoggerFactory.getLogger(ConfigurationFileUtils.class);
5757
private static final String lineSeparator = "\n";
5858
private static final String license =
5959
new StringJoiner(lineSeparator)
@@ -74,11 +74,9 @@ public class ConfigurationFileUtils {
7474
.add("# specific language governing permissions and limitations")
7575
.add("# under the License.")
7676
.toString();
77-
private static final String EFFECTIVE_MODE = "effectiveMode:";
78-
private static final String DATATYPE = "Datatype:";
79-
private static final String EFFECTIVE_MODE_HOT_RELOAD = "hot_reload";
80-
private static final String EFFECTIVE_MODE_RESTART = "restart";
81-
private static final String EFFECTIVE_MODE_FIRST_START = "first_start";
77+
private static final String EFFECTIVE_MODE_PREFIX = "effectiveMode:";
78+
private static final String EFFECTIVE_NODE_TYPE_PREFIX = "effectiveNodeType:";
79+
private static final String DATATYPE_PREFIX = "Datatype:";
8280
private static Map<String, DefaultConfigurationItem> configuration2DefaultValue;
8381

8482
// This is a temporary implementations
@@ -113,9 +111,19 @@ public class ConfigurationFileUtils {
113111

114112
private static final Map<String, String> lastAppliedProperties = new HashMap<>();
115113

116-
public static void updateLastAppliedProperties(TrimProperties properties) {
114+
public static void updateLastAppliedProperties(
115+
TrimProperties properties, boolean isHotReloading) throws IOException {
116+
loadConfigurationDefaultValueFromTemplate();
117117
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
118118
String key = entry.getKey().toString();
119+
DefaultConfigurationItem defaultConfigurationItem = configuration2DefaultValue.get(key);
120+
if (defaultConfigurationItem == null) {
121+
continue;
122+
}
123+
if (isHotReloading
124+
&& defaultConfigurationItem.effectiveMode != EffectiveModeType.HOT_RELOAD) {
125+
continue;
126+
}
119127
String value = entry.getValue() == null ? null : entry.getValue().toString();
120128
lastAppliedProperties.put(key, value);
121129
}
@@ -373,33 +381,37 @@ public static Map<String, DefaultConfigurationItem> getConfigurationItemsFromTem
373381
.getResourceAsStream(CommonConfig.SYSTEM_CONFIG_TEMPLATE_NAME);
374382
InputStreamReader isr = new InputStreamReader(inputStream);
375383
BufferedReader reader = new BufferedReader(isr)) {
376-
String effectiveMode = null;
377-
String dataType = null;
384+
EffectiveModeType effectiveMode = null;
378385
StringBuilder description = new StringBuilder();
379386
String line;
380387
while ((line = reader.readLine()) != null) {
381388
line = line.trim();
382389
if (line.isEmpty()) {
383390
description = new StringBuilder();
384-
dataType = null;
385391
effectiveMode = null;
386392
continue;
387393
}
388394
if (line.startsWith("#")) {
389395
String comment = line.substring(1).trim();
390-
if (description.length() > 0) {
391-
if (comment.startsWith(EFFECTIVE_MODE)) {
392-
effectiveMode = comment.substring(EFFECTIVE_MODE.length()).trim();
393-
continue;
394-
} else if (comment.startsWith(DATATYPE)) {
395-
dataType = comment.substring(DATATYPE.length()).trim();
396-
continue;
397-
} else {
398-
description.append(" ");
399-
}
396+
if (comment.isEmpty()) {
397+
continue;
398+
}
399+
boolean needSeperateLine = false;
400+
if (comment.startsWith(EFFECTIVE_MODE_PREFIX)) {
401+
effectiveMode =
402+
EffectiveModeType.getEffectiveMode(
403+
comment.substring(EFFECTIVE_MODE_PREFIX.length()).trim());
404+
needSeperateLine = true;
405+
} else if (comment.startsWith(DATATYPE_PREFIX)) {
406+
needSeperateLine = true;
407+
} else {
408+
description.append(" ");
400409
}
401410
if (withDesc) {
402411
description.append(comment);
412+
if (needSeperateLine) {
413+
description.append(lineSeparator);
414+
}
403415
}
404416
} else {
405417
int equalsIndex = line.indexOf('=');
@@ -408,11 +420,7 @@ public static Map<String, DefaultConfigurationItem> getConfigurationItemsFromTem
408420
items.put(
409421
key,
410422
new DefaultConfigurationItem(
411-
key,
412-
value,
413-
withDesc ? description.toString().trim() : null,
414-
effectiveMode,
415-
dataType));
423+
key, value, withDesc ? description.toString().trim() : null, effectiveMode));
416424
}
417425
}
418426
} catch (IOException e) {
@@ -426,16 +434,33 @@ public static class DefaultConfigurationItem {
426434
public String name;
427435
public String value;
428436
public String description;
429-
public String effectiveMode;
430-
public String dataType;
437+
public EffectiveModeType effectiveMode;
431438

432439
public DefaultConfigurationItem(
433-
String name, String value, String description, String effectiveMode, String dataType) {
440+
String name, String value, String description, EffectiveModeType effectiveMode) {
434441
this.name = name;
435442
this.value = value;
436443
this.description = description;
437-
this.effectiveMode = effectiveMode;
438-
this.dataType = dataType;
444+
this.effectiveMode = effectiveMode == null ? EffectiveModeType.UNKNOWN : effectiveMode;
445+
}
446+
}
447+
448+
public enum EffectiveModeType {
449+
HOT_RELOAD,
450+
FIRST_START,
451+
RESTART,
452+
UNKNOWN;
453+
454+
public static EffectiveModeType getEffectiveMode(String effectiveMode) {
455+
if (HOT_RELOAD.name().equalsIgnoreCase(effectiveMode)) {
456+
return HOT_RELOAD;
457+
} else if (FIRST_START.name().equalsIgnoreCase(effectiveMode)) {
458+
return FIRST_START;
459+
} else if (RESTART.name().equalsIgnoreCase(effectiveMode)) {
460+
return RESTART;
461+
} else {
462+
return UNKNOWN;
463+
}
439464
}
440465
}
441466
}

0 commit comments

Comments
 (0)