This is an automated email from the ASF dual-hosted git repository. shuwenwei pushed a commit to branch showConfigurationSQL in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 895410e595179aa572f7d098cd4ba3e52d367bd4 Author: shuwenwei <[email protected]> AuthorDate: Fri Aug 29 10:22:01 2025 +0800 add enum --- .../confignode/conf/ConfigNodeDescriptor.java | 7 +- .../org/apache/iotdb/db/conf/IoTDBDescriptor.java | 5 +- .../iotdb/commons/conf/ConfigurationFileUtils.java | 85 ++++++++++++++-------- 3 files changed, 62 insertions(+), 35 deletions(-) diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeDescriptor.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeDescriptor.java index 64b71199eb7..3243c4634ae 100644 --- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeDescriptor.java +++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/conf/ConfigNodeDescriptor.java @@ -147,7 +147,8 @@ public class ConfigNodeDescriptor { } private void loadProperties(TrimProperties properties) throws BadNodeUrlException, IOException { - loadHotModifiedProps(properties); + ConfigurationFileUtils.updateLastAppliedProperties(properties, false); + conf.setClusterName(properties.getProperty(IoTDBConstant.CLUSTER_NAME, conf.getClusterName())); conf.setInternalAddress( properties.getProperty(IoTDBConstant.CN_INTERNAL_ADDRESS, conf.getInternalAddress())); @@ -764,8 +765,8 @@ public class ConfigNodeDescriptor { } } - public void loadHotModifiedProps(TrimProperties properties) { - ConfigurationFileUtils.updateLastAppliedProperties(properties); + public void loadHotModifiedProps(TrimProperties properties) throws IOException { + ConfigurationFileUtils.updateLastAppliedProperties(properties, true); conf.setClusterName(properties.getProperty(IoTDBConstant.CLUSTER_NAME, conf.getClusterName())); } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java index 2b24ee972af..69081fe62be 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java @@ -255,6 +255,7 @@ public class IoTDBDescriptor { } public void loadProperties(TrimProperties properties) throws BadNodeUrlException, IOException { + ConfigurationFileUtils.updateLastAppliedProperties(properties, false); conf.setClusterName(properties.getProperty(IoTDBConstant.CLUSTER_NAME, conf.getClusterName())); conf.setRpcAddress(properties.getProperty(IoTDBConstant.DN_RPC_ADDRESS, conf.getRpcAddress())); @@ -1960,8 +1961,8 @@ public class IoTDBDescriptor { } public synchronized void loadHotModifiedProps(TrimProperties properties) - throws QueryProcessException { - ConfigurationFileUtils.updateLastAppliedProperties(properties); + throws QueryProcessException, IOException { + ConfigurationFileUtils.updateLastAppliedProperties(properties, true); try { // update data dirs String dataDirs = properties.getProperty("dn_data_dirs", null); diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/ConfigurationFileUtils.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/ConfigurationFileUtils.java index 61ea506face..5493a761709 100644 --- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/ConfigurationFileUtils.java +++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/ConfigurationFileUtils.java @@ -53,7 +53,7 @@ public class ConfigurationFileUtils { private static final String lockFileSuffix = ".lock"; private static final long maxTimeMillsToAcquireLock = TimeUnit.SECONDS.toMillis(20); private static final long waitTimeMillsPerCheck = TimeUnit.MILLISECONDS.toMillis(100); - private static Logger logger = LoggerFactory.getLogger(ConfigurationFileUtils.class); + private static final Logger logger = LoggerFactory.getLogger(ConfigurationFileUtils.class); private static final String lineSeparator = "\n"; private static final String license = new StringJoiner(lineSeparator) @@ -74,11 +74,9 @@ public class ConfigurationFileUtils { .add("# specific language governing permissions and limitations") .add("# under the License.") .toString(); - private static final String EFFECTIVE_MODE = "effectiveMode:"; - private static final String DATATYPE = "Datatype:"; - private static final String EFFECTIVE_MODE_HOT_RELOAD = "hot_reload"; - private static final String EFFECTIVE_MODE_RESTART = "restart"; - private static final String EFFECTIVE_MODE_FIRST_START = "first_start"; + private static final String EFFECTIVE_MODE_PREFIX = "effectiveMode:"; + private static final String EFFECTIVE_NODE_TYPE_PREFIX = "effectiveNodeType:"; + private static final String DATATYPE_PREFIX = "Datatype:"; private static Map<String, DefaultConfigurationItem> configuration2DefaultValue; // This is a temporary implementations @@ -113,9 +111,19 @@ public class ConfigurationFileUtils { private static final Map<String, String> lastAppliedProperties = new HashMap<>(); - public static void updateLastAppliedProperties(TrimProperties properties) { + public static void updateLastAppliedProperties( + TrimProperties properties, boolean isHotReloading) throws IOException { + loadConfigurationDefaultValueFromTemplate(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String key = entry.getKey().toString(); + DefaultConfigurationItem defaultConfigurationItem = configuration2DefaultValue.get(key); + if (defaultConfigurationItem == null) { + continue; + } + if (isHotReloading + && defaultConfigurationItem.effectiveMode != EffectiveModeType.HOT_RELOAD) { + continue; + } String value = entry.getValue() == null ? null : entry.getValue().toString(); lastAppliedProperties.put(key, value); } @@ -373,33 +381,37 @@ public class ConfigurationFileUtils { .getResourceAsStream(CommonConfig.SYSTEM_CONFIG_TEMPLATE_NAME); InputStreamReader isr = new InputStreamReader(inputStream); BufferedReader reader = new BufferedReader(isr)) { - String effectiveMode = null; - String dataType = null; + EffectiveModeType effectiveMode = null; StringBuilder description = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { line = line.trim(); if (line.isEmpty()) { description = new StringBuilder(); - dataType = null; effectiveMode = null; continue; } if (line.startsWith("#")) { String comment = line.substring(1).trim(); - if (description.length() > 0) { - if (comment.startsWith(EFFECTIVE_MODE)) { - effectiveMode = comment.substring(EFFECTIVE_MODE.length()).trim(); - continue; - } else if (comment.startsWith(DATATYPE)) { - dataType = comment.substring(DATATYPE.length()).trim(); - continue; - } else { - description.append(" "); - } + if (comment.isEmpty()) { + continue; + } + boolean needSeperateLine = false; + if (comment.startsWith(EFFECTIVE_MODE_PREFIX)) { + effectiveMode = + EffectiveModeType.getEffectiveMode( + comment.substring(EFFECTIVE_MODE_PREFIX.length()).trim()); + needSeperateLine = true; + } else if (comment.startsWith(DATATYPE_PREFIX)) { + needSeperateLine = true; + } else { + description.append(" "); } if (withDesc) { description.append(comment); + if (needSeperateLine) { + description.append(lineSeparator); + } } } else { int equalsIndex = line.indexOf('='); @@ -408,11 +420,7 @@ public class ConfigurationFileUtils { items.put( key, new DefaultConfigurationItem( - key, - value, - withDesc ? description.toString().trim() : null, - effectiveMode, - dataType)); + key, value, withDesc ? description.toString().trim() : null, effectiveMode)); } } } catch (IOException e) { @@ -426,16 +434,33 @@ public class ConfigurationFileUtils { public String name; public String value; public String description; - public String effectiveMode; - public String dataType; + public EffectiveModeType effectiveMode; public DefaultConfigurationItem( - String name, String value, String description, String effectiveMode, String dataType) { + String name, String value, String description, EffectiveModeType effectiveMode) { this.name = name; this.value = value; this.description = description; - this.effectiveMode = effectiveMode; - this.dataType = dataType; + this.effectiveMode = effectiveMode == null ? EffectiveModeType.UNKNOWN : effectiveMode; + } + } + + public enum EffectiveModeType { + HOT_RELOAD, + FIRST_START, + RESTART, + UNKNOWN; + + public static EffectiveModeType getEffectiveMode(String effectiveMode) { + if (HOT_RELOAD.name().equalsIgnoreCase(effectiveMode)) { + return HOT_RELOAD; + } else if (FIRST_START.name().equalsIgnoreCase(effectiveMode)) { + return FIRST_START; + } else if (RESTART.name().equalsIgnoreCase(effectiveMode)) { + return RESTART; + } else { + return UNKNOWN; + } } } }
