This is an automated email from the ASF dual-hosted git repository.
jiangtian 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 b3892dac3cc Add TrimProperties to trim properties auto (#14289)
b3892dac3cc is described below
commit b3892dac3cc968df5f8dad83d5ea180e4d6f69a7
Author: Yukim1 <[email protected]>
AuthorDate: Wed Dec 4 09:52:56 2024 +0800
Add TrimProperties to trim properties auto (#14289)
* Add TrimProperties to trim properties auto
* add license
---
iotdb-core/confignode/pom.xml | 6 ++
.../confignode/conf/ConfigNodeDescriptor.java | 18 +++---
.../iotdb/confignode/manager/ConfigManager.java | 4 +-
.../confignode/conf/ConfigNodePropertiesTest.java | 50 +++++++++++++++
.../org/apache/iotdb/db/conf/IoTDBDescriptor.java | 72 ++++++++++++----------
.../db/conf/rest/IoTDBRestServiceDescriptor.java | 49 ++++++++-------
.../iotdb/db/storageengine/StorageEngine.java | 4 +-
.../iotdb/db/{utils => conf}/PropertiesTest.java | 35 ++++++++++-
.../metrics/config/MetricConfigDescriptor.java | 6 +-
.../iotdb/commons/conf/CommonDescriptor.java | 9 ++-
.../apache/iotdb/commons/conf/TrimProperties.java | 50 +++++++++++++++
11 files changed, 224 insertions(+), 79 deletions(-)
diff --git a/iotdb-core/confignode/pom.xml b/iotdb-core/confignode/pom.xml
index 6857cfd6069..3b7998f091e 100644
--- a/iotdb-core/confignode/pom.xml
+++ b/iotdb-core/confignode/pom.xml
@@ -154,6 +154,12 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>com.tngtech.archunit</groupId>
+ <artifactId>archunit</artifactId>
+ <version>1.3.0</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
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 77190535876..918c1856a00 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
@@ -23,6 +23,7 @@ import org.apache.iotdb.commons.conf.CommonConfig;
import org.apache.iotdb.commons.conf.CommonDescriptor;
import org.apache.iotdb.commons.conf.ConfigurationFileUtils;
import org.apache.iotdb.commons.conf.IoTDBConstant;
+import org.apache.iotdb.commons.conf.TrimProperties;
import org.apache.iotdb.commons.exception.BadNodeUrlException;
import org.apache.iotdb.commons.schema.SchemaConstant;
import org.apache.iotdb.commons.utils.NodeUrlUtils;
@@ -46,7 +47,6 @@ import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Optional;
-import java.util.Properties;
public class ConfigNodeDescriptor {
private static final Logger LOGGER =
LoggerFactory.getLogger(ConfigNodeDescriptor.class);
@@ -118,13 +118,13 @@ public class ConfigNodeDescriptor {
}
private void loadProps() {
- Properties commonProperties = new Properties();
+ TrimProperties trimProperties = new TrimProperties();
URL url = getPropsUrl(CommonConfig.SYSTEM_CONFIG_NAME);
if (url != null) {
try (InputStream inputStream = url.openStream()) {
LOGGER.info("start reading ConfigNode conf file: {}", url);
- commonProperties.load(new InputStreamReader(inputStream,
StandardCharsets.UTF_8));
- loadProperties(commonProperties);
+ trimProperties.load(new InputStreamReader(inputStream,
StandardCharsets.UTF_8));
+ loadProperties(trimProperties);
} catch (IOException | BadNodeUrlException e) {
LOGGER.error("Couldn't load ConfigNode conf file, reject ConfigNode
startup.", e);
System.exit(-1);
@@ -133,7 +133,7 @@ public class ConfigNodeDescriptor {
commonDescriptor
.getConfig()
.updatePath(System.getProperty(ConfigNodeConstant.CONFIGNODE_HOME,
null));
- MetricConfigDescriptor.getInstance().loadProps(commonProperties, true);
+ MetricConfigDescriptor.getInstance().loadProps(trimProperties, true);
MetricConfigDescriptor.getInstance()
.getMetricConfig()
.updateRpcInstance(NodeType.CONFIGNODE,
SchemaConstant.SYSTEM_DATABASE);
@@ -145,7 +145,7 @@ public class ConfigNodeDescriptor {
}
}
- private void loadProperties(Properties properties) throws
BadNodeUrlException, IOException {
+ private void loadProperties(TrimProperties properties) throws
BadNodeUrlException, IOException {
conf.setClusterName(
properties.getProperty(IoTDBConstant.CLUSTER_NAME,
conf.getClusterName()).trim());
@@ -401,7 +401,7 @@ public class ConfigNodeDescriptor {
loadCQConfig(properties);
}
- private void loadRatisConsensusConfig(Properties properties) {
+ private void loadRatisConsensusConfig(TrimProperties properties) {
conf.setDataRegionRatisConsensusLogAppenderBufferSize(
Long.parseLong(
properties
@@ -813,7 +813,7 @@ public class ConfigNodeDescriptor {
.trim()));
}
- private void loadCQConfig(Properties properties) {
+ private void loadCQConfig(TrimProperties properties) {
int cqSubmitThread =
Integer.parseInt(
properties
@@ -871,7 +871,7 @@ public class ConfigNodeDescriptor {
}
}
- public void loadHotModifiedProps(Properties properties) {
+ public void loadHotModifiedProps(TrimProperties properties) {
Optional.ofNullable(properties.getProperty(IoTDBConstant.CLUSTER_NAME))
.ifPresent(conf::setClusterName);
}
diff --git
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
index 6b1f32f16b0..43383319f85 100644
---
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
+++
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/ConfigManager.java
@@ -42,6 +42,7 @@ import org.apache.iotdb.commons.conf.CommonConfig;
import org.apache.iotdb.commons.conf.CommonDescriptor;
import org.apache.iotdb.commons.conf.ConfigurationFileUtils;
import org.apache.iotdb.commons.conf.IoTDBConstant;
+import org.apache.iotdb.commons.conf.TrimProperties;
import org.apache.iotdb.commons.exception.IllegalPathException;
import org.apache.iotdb.commons.exception.MetadataException;
import org.apache.iotdb.commons.path.PartialPath;
@@ -257,7 +258,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -1672,7 +1672,7 @@ public class ConfigManager implements IManager {
return tsStatus;
}
File file = new File(url.getFile());
- Properties properties = new Properties();
+ TrimProperties properties = new TrimProperties();
properties.putAll(req.getConfigs());
try {
ConfigurationFileUtils.updateConfigurationFile(file, properties);
diff --git
a/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/conf/ConfigNodePropertiesTest.java
b/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/conf/ConfigNodePropertiesTest.java
new file mode 100644
index 00000000000..1101fcc3f11
--- /dev/null
+++
b/iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/conf/ConfigNodePropertiesTest.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.confignode.conf;
+
+import com.tngtech.archunit.core.domain.JavaClasses;
+import com.tngtech.archunit.core.importer.ClassFileImporter;
+import com.tngtech.archunit.core.importer.ImportOption;
+import com.tngtech.archunit.lang.ArchRule;
+import org.junit.Test;
+
+import java.util.Properties;
+
+import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
+
+public class ConfigNodePropertiesTest {
+ @Test
+ public void TrimPropertiesOnly() {
+ JavaClasses allClasses =
+ new ClassFileImporter()
+ .withImportOption(new ImportOption.DoNotIncludeTests())
+ .importPackages("org.apache.iotdb");
+
+ ArchRule rule =
+ noClasses()
+ .that()
+
.areAssignableTo("org.apache.iotdb.confignode.conf.ConfigNodeDescriptor")
+ .should()
+ .callMethod(Properties.class, "getProperty", String.class)
+ .orShould()
+ .callMethod(Properties.class, "getProperty", String.class,
String.class);
+
+ rule.check(allClasses);
+ }
+}
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 5411556ca64..37490ec97f2 100755
---
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
@@ -22,6 +22,7 @@ import org.apache.iotdb.commons.conf.CommonConfig;
import org.apache.iotdb.commons.conf.CommonDescriptor;
import org.apache.iotdb.commons.conf.ConfigurationFileUtils;
import org.apache.iotdb.commons.conf.IoTDBConstant;
+import org.apache.iotdb.commons.conf.TrimProperties;
import org.apache.iotdb.commons.exception.BadNodeUrlException;
import org.apache.iotdb.commons.schema.SchemaConstant;
import org.apache.iotdb.commons.service.metric.MetricService;
@@ -129,8 +130,10 @@ public class IoTDBDescriptor {
for (IPropertiesLoader loader : propertiesLoaderServiceLoader) {
LOGGER.info("Will reload properties from {} ",
loader.getClass().getName());
Properties properties = loader.loadProperties();
+ TrimProperties trimProperties = new TrimProperties();
+ trimProperties.putAll(properties);
try {
- loadProperties(properties);
+ loadProperties(trimProperties);
} catch (Exception e) {
LOGGER.error(
"Failed to reload properties from {}, reject DataNode startup.",
@@ -197,7 +200,7 @@ public class IoTDBDescriptor {
/** load a property file and set TsfileDBConfig variables. */
@SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity
warning
private void loadProps() {
- Properties commonProperties = new Properties();
+ TrimProperties commonProperties = new TrimProperties();
// if new properties file exist, skip old properties files
URL url = getPropsUrl(CommonConfig.SYSTEM_CONFIG_NAME);
if (url != null) {
@@ -232,7 +235,7 @@ public class IoTDBDescriptor {
}
}
- public void loadProperties(Properties properties) throws
BadNodeUrlException, IOException {
+ public void loadProperties(TrimProperties properties) throws
BadNodeUrlException, IOException {
conf.setClusterName(
Optional.ofNullable(
properties.getProperty(IoTDBConstant.CLUSTER_NAME,
conf.getClusterName()))
@@ -1548,13 +1551,13 @@ public class IoTDBDescriptor {
loadIoTConsensusV2Props(properties);
}
- private void reloadConsensusProps(Properties properties) throws IOException {
+ private void reloadConsensusProps(TrimProperties properties) throws
IOException {
loadIoTConsensusProps(properties);
loadIoTConsensusV2Props(properties);
DataRegionConsensusImpl.reloadConsensusConfig();
}
- private void loadIoTConsensusProps(Properties properties) throws IOException
{
+ private void loadIoTConsensusProps(TrimProperties properties) throws
IOException {
conf.setMaxLogEntriesNumPerBatch(
Integer.parseInt(
Optional.ofNullable(
@@ -1612,7 +1615,7 @@ public class IoTDBDescriptor {
"region_migration_speed_limit_bytes_per_second"))));
}
- private void loadIoTConsensusV2Props(Properties properties) throws
IOException {
+ private void loadIoTConsensusV2Props(TrimProperties properties) throws
IOException {
conf.setIotConsensusV2PipelineSize(
Integer.parseInt(
Optional.ofNullable(
@@ -1636,7 +1639,7 @@ public class IoTDBDescriptor {
.orElse(ConfigurationFileUtils.getConfigurationDefaultValue("iot_consensus_v2_mode")));
}
- private void loadAuthorCache(Properties properties) {
+ private void loadAuthorCache(TrimProperties properties) {
conf.setAuthorCacheSize(
Integer.parseInt(
Optional.ofNullable(
@@ -1654,7 +1657,7 @@ public class IoTDBDescriptor {
.orElse(String.valueOf(conf.getAuthorCacheExpireTime()))));
}
- private void loadWALProps(Properties properties) throws IOException {
+ private void loadWALProps(TrimProperties properties) throws IOException {
conf.setWalMode(
WALMode.valueOf(
(Optional.ofNullable(properties.getProperty("wal_mode",
conf.getWalMode().toString()))
@@ -1710,7 +1713,7 @@ public class IoTDBDescriptor {
loadWALHotModifiedProps(properties);
}
- private void loadCompactionHotModifiedProps(Properties properties)
+ private void loadCompactionHotModifiedProps(TrimProperties properties)
throws InterruptedException, IOException {
boolean compactionTaskConfigHotModified =
loadCompactionTaskHotModifiedProps(properties);
if (compactionTaskConfigHotModified) {
@@ -1754,7 +1757,7 @@ public class IoTDBDescriptor {
.orElse(Boolean.toString(conf.isEnableAutoRepairCompaction()))));
}
- private boolean loadCompactionTaskHotModifiedProps(Properties properties)
throws IOException {
+ private boolean loadCompactionTaskHotModifiedProps(TrimProperties
properties) throws IOException {
boolean configModified = false;
// update merge_write_throughput_mb_per_sec
int compactionWriteThroughput =
conf.getCompactionWriteThroughputMbPerSec();
@@ -2019,7 +2022,7 @@ public class IoTDBDescriptor {
return configModified;
}
- private boolean loadCompactionThreadCountHotModifiedProps(Properties
properties)
+ private boolean loadCompactionThreadCountHotModifiedProps(TrimProperties
properties)
throws IOException {
int newConfigCompactionThreadCount =
Integer.parseInt(
@@ -2053,7 +2056,7 @@ public class IoTDBDescriptor {
return true;
}
- private boolean loadCompactionSubTaskCountHotModifiedProps(Properties
properties)
+ private boolean loadCompactionSubTaskCountHotModifiedProps(TrimProperties
properties)
throws IOException {
int newConfigSubtaskNum =
Integer.parseInt(
@@ -2077,7 +2080,8 @@ public class IoTDBDescriptor {
return true;
}
- private void loadCompactionIsEnabledHotModifiedProps(Properties properties)
throws IOException {
+ private void loadCompactionIsEnabledHotModifiedProps(TrimProperties
properties)
+ throws IOException {
boolean isCompactionEnabled =
conf.isEnableSeqSpaceCompaction()
|| conf.isEnableUnseqSpaceCompaction()
@@ -2130,7 +2134,7 @@ public class IoTDBDescriptor {
conf.setEnableUnseqSpaceCompaction(newConfigEnableUnseqSpaceCompaction);
}
- private void loadWALHotModifiedProps(Properties properties) throws
IOException {
+ private void loadWALHotModifiedProps(TrimProperties properties) throws
IOException {
long walAsyncModeFsyncDelayInMs =
Long.parseLong(
Optional.ofNullable(
@@ -2257,7 +2261,7 @@ public class IoTDBDescriptor {
}
}
- private String getWalThrottleThreshold(Properties prop) throws IOException {
+ private String getWalThrottleThreshold(TrimProperties prop) throws
IOException {
String old_throttleThreshold =
prop.getProperty(DEFAULT_WAL_THRESHOLD_NAME[0], null);
if (old_throttleThreshold != null) {
LOGGER.warn(
@@ -2298,7 +2302,7 @@ public class IoTDBDescriptor {
return Math.max(Math.min(newThrottleThreshold, MAX_THROTTLE_THRESHOLD),
MIN_THROTTLE_THRESHOLD);
}
- private void loadAutoCreateSchemaProps(Properties properties) throws
IOException {
+ private void loadAutoCreateSchemaProps(TrimProperties properties) throws
IOException {
conf.setAutoCreateSchemaEnabled(
Boolean.parseBoolean(
Optional.ofNullable(
@@ -2411,7 +2415,7 @@ public class IoTDBDescriptor {
.orElse(ConfigurationFileUtils.getConfigurationDefaultValue("default_text_encoding")));
}
- private void loadTsFileProps(Properties properties) throws IOException {
+ private void loadTsFileProps(TrimProperties properties) throws IOException {
TSFileDescriptor.getInstance()
.getConfig()
.setGroupSizeInByte(
@@ -2544,7 +2548,7 @@ public class IoTDBDescriptor {
}
// Mqtt related
- private void loadMqttProps(Properties properties) {
+ private void loadMqttProps(TrimProperties properties) {
conf.setMqttDir(
Optional.ofNullable(properties.getProperty("mqtt_root_dir",
conf.getMqttDir()))
.map(String::trim)
@@ -2589,7 +2593,7 @@ public class IoTDBDescriptor {
}
// timed flush memtable
- private void loadTimedService(Properties properties) throws IOException {
+ private void loadTimedService(TrimProperties properties) throws IOException {
conf.setEnableTimedFlushSeqMemtable(
Boolean.parseBoolean(
Optional.ofNullable(
@@ -2684,7 +2688,7 @@ public class IoTDBDescriptor {
return tierDataDirs;
}
- public synchronized void loadHotModifiedProps(Properties properties)
+ public synchronized void loadHotModifiedProps(TrimProperties properties)
throws QueryProcessException {
try {
// update data dirs
@@ -2860,7 +2864,7 @@ public class IoTDBDescriptor {
return;
}
- Properties commonProperties = new Properties();
+ TrimProperties commonProperties = new TrimProperties();
try (InputStream inputStream = url.openStream()) {
LOGGER.info("Start to reload config file {}", url);
commonProperties.load(new InputStreamReader(inputStream,
StandardCharsets.UTF_8));
@@ -2876,7 +2880,7 @@ public class IoTDBDescriptor {
reloadMetricProperties(commonProperties);
}
- public void reloadMetricProperties(Properties properties) {
+ public void reloadMetricProperties(TrimProperties properties) {
ReloadLevel reloadLevel =
MetricConfigDescriptor.getInstance().loadHotProps(properties, false);
LOGGER.info("Reload metric service in level {}", reloadLevel);
if (reloadLevel == ReloadLevel.RESTART_INTERNAL_REPORTER) {
@@ -2893,7 +2897,7 @@ public class IoTDBDescriptor {
}
}
- private void initMemoryAllocate(Properties properties) {
+ private void initMemoryAllocate(TrimProperties properties) {
String memoryAllocateProportion =
properties.getProperty("datanode_memory_proportion", null);
if (memoryAllocateProportion == null) {
memoryAllocateProportion =
@@ -3008,7 +3012,7 @@ public class IoTDBDescriptor {
}
@SuppressWarnings("java:S3518")
- private void initStorageEngineAllocate(Properties properties) {
+ private void initStorageEngineAllocate(TrimProperties properties) {
long storageMemoryTotal = conf.getAllocateMemoryForStorageEngine();
String valueOfStorageEngineMemoryProportion =
properties.getProperty("storage_engine_memory_proportion");
@@ -3063,7 +3067,7 @@ public class IoTDBDescriptor {
}
@SuppressWarnings("squid:S3518")
- private void initSchemaMemoryAllocate(Properties properties) {
+ private void initSchemaMemoryAllocate(TrimProperties properties) {
long schemaMemoryTotal = conf.getAllocateMemoryForSchema();
String schemaMemoryPortionInput =
properties.getProperty("schema_memory_proportion");
@@ -3121,7 +3125,7 @@ public class IoTDBDescriptor {
LOGGER.info("allocateMemoryForPartitionCache = {}",
conf.getAllocateMemoryForPartitionCache());
}
- private void loadLoadTsFileProps(Properties properties) {
+ private void loadLoadTsFileProps(TrimProperties properties) {
conf.setMaxAllocateMemoryRatioForLoad(
Double.parseDouble(
Optional.ofNullable(
@@ -3235,7 +3239,7 @@ public class IoTDBDescriptor {
}
}
- private void loadLoadTsFileHotModifiedProp(Properties properties) throws
IOException {
+ private void loadLoadTsFileHotModifiedProp(TrimProperties properties) throws
IOException {
conf.setLoadCleanupTaskExecutionDelayTimeSeconds(
Long.parseLong(
Optional.ofNullable(
@@ -3297,7 +3301,7 @@ public class IoTDBDescriptor {
}
@SuppressWarnings("squid:S3518") // "proportionSum" can't be zero
- private void loadUDFProps(Properties properties) {
+ private void loadUDFProps(TrimProperties properties) {
String initialByteArrayLengthForMemoryControl =
properties.getProperty("udf_initial_byte_array_length_for_memory_control");
if (initialByteArrayLengthForMemoryControl != null) {
@@ -3345,7 +3349,7 @@ public class IoTDBDescriptor {
}
}
- private void initThriftSSL(Properties properties) {
+ private void initThriftSSL(TrimProperties properties) {
conf.setEnableSSL(
Boolean.parseBoolean(
Optional.ofNullable(
@@ -3363,7 +3367,7 @@ public class IoTDBDescriptor {
.orElse(conf.getKeyStorePath()));
}
- private void loadTriggerProps(Properties properties) {
+ private void loadTriggerProps(TrimProperties properties) {
conf.setTriggerDir(properties.getProperty("trigger_lib_dir",
conf.getTriggerDir()).trim());
conf.setRetryNumToFindStatefulTrigger(
Integer.parseInt(
@@ -3435,7 +3439,7 @@ public class IoTDBDescriptor {
.orElse(Integer.toString(conf.getTriggerForwardMQTTPoolSize()))));
}
- private void loadPipeProps(Properties properties) {
+ private void loadPipeProps(TrimProperties properties) {
conf.setPipeLibDir(
Optional.ofNullable(properties.getProperty("pipe_lib_dir",
conf.getPipeLibDir()))
.map(String::trim)
@@ -3472,7 +3476,7 @@ public class IoTDBDescriptor {
.orElse(conf.getIotConsensusV2DeletionFileDir()));
}
- private void loadCQProps(Properties properties) {
+ private void loadCQProps(TrimProperties properties) {
conf.setContinuousQueryThreadNum(
Integer.parseInt(
Optional.ofNullable(
@@ -3492,7 +3496,7 @@ public class IoTDBDescriptor {
false));
}
- public void loadClusterProps(Properties properties) throws IOException {
+ public void loadClusterProps(TrimProperties properties) throws IOException {
String configNodeUrls =
properties.getProperty(IoTDBConstant.DN_SEED_CONFIG_NODE);
if (configNodeUrls == null) {
configNodeUrls =
properties.getProperty(IoTDBConstant.DN_TARGET_CONFIG_NODE_LIST);
@@ -3553,7 +3557,7 @@ public class IoTDBDescriptor {
.orElse(Long.toString(conf.getJoinClusterRetryIntervalMs()))));
}
- public void loadShuffleProps(Properties properties) {
+ public void loadShuffleProps(TrimProperties properties) {
conf.setMppDataExchangePort(
Integer.parseInt(
Optional.ofNullable(
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/rest/IoTDBRestServiceDescriptor.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/rest/IoTDBRestServiceDescriptor.java
index 6e5526769b5..6236ad83361 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/rest/IoTDBRestServiceDescriptor.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/rest/IoTDBRestServiceDescriptor.java
@@ -20,6 +20,7 @@ package org.apache.iotdb.db.conf.rest;
import org.apache.iotdb.commons.conf.CommonConfig;
import org.apache.iotdb.commons.conf.IoTDBConstant;
+import org.apache.iotdb.commons.conf.TrimProperties;
import org.apache.iotdb.db.conf.IoTDBConfig;
import org.slf4j.Logger;
@@ -34,7 +35,6 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Optional;
-import java.util.Properties;
public class IoTDBRestServiceDescriptor {
private static final Logger logger =
LoggerFactory.getLogger(IoTDBRestServiceDescriptor.class);
@@ -44,9 +44,9 @@ public class IoTDBRestServiceDescriptor {
protected IoTDBRestServiceDescriptor() {
URL systemConfig = getPropsUrl(CommonConfig.SYSTEM_CONFIG_NAME);
if (systemConfig != null) {
- Properties properties = loadProps(CommonConfig.SYSTEM_CONFIG_NAME);
- if (properties != null) {
- loadProps(properties);
+ TrimProperties trimProperties =
loadProps(CommonConfig.SYSTEM_CONFIG_NAME);
+ if (trimProperties != null) {
+ loadProps(trimProperties);
}
}
}
@@ -57,7 +57,7 @@ public class IoTDBRestServiceDescriptor {
/** load an property file. */
@SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity
warning
- private Properties loadProps(String configName) {
+ private TrimProperties loadProps(String configName) {
URL url = getPropsUrl(configName);
if (url == null) {
logger.warn("Couldn't load the REST Service configuration from any of
the known sources.");
@@ -65,9 +65,9 @@ public class IoTDBRestServiceDescriptor {
}
try (InputStream inputStream = url.openStream()) {
logger.info("Start to read config file {}", url);
- Properties properties = new Properties();
- properties.load(new InputStreamReader(inputStream,
StandardCharsets.UTF_8));
- return properties;
+ TrimProperties trimProperties = new TrimProperties();
+ trimProperties.load(new InputStreamReader(inputStream,
StandardCharsets.UTF_8));
+ return trimProperties;
} catch (FileNotFoundException e) {
logger.warn("REST service fail to find config file {}", url, e);
} catch (IOException e) {
@@ -78,25 +78,25 @@ public class IoTDBRestServiceDescriptor {
return null;
}
- private void loadProps(Properties properties) {
+ private void loadProps(TrimProperties trimProperties) {
conf.setEnableRestService(
Boolean.parseBoolean(
Optional.ofNullable(
- properties.getProperty(
+ trimProperties.getProperty(
"enable_rest_service",
Boolean.toString(conf.isEnableRestService())))
.map(String::trim)
.orElse(Boolean.toString(conf.isEnableRestService()))));
conf.setRestServicePort(
Integer.parseInt(
Optional.ofNullable(
- properties.getProperty(
+ trimProperties.getProperty(
"rest_service_port",
Integer.toString(conf.getRestServicePort())))
.map(String::trim)
.orElse(Integer.toString(conf.getRestServicePort()))));
conf.setRestQueryDefaultRowSizeLimit(
Integer.parseInt(
Optional.ofNullable(
- properties.getProperty(
+ trimProperties.getProperty(
"rest_query_default_row_size_limit",
Integer.toString(conf.getRestQueryDefaultRowSizeLimit())))
.map(String::trim)
@@ -104,7 +104,7 @@ public class IoTDBRestServiceDescriptor {
conf.setEnableSwagger(
Boolean.parseBoolean(
Optional.ofNullable(
- properties.getProperty(
+ trimProperties.getProperty(
"enable_swagger",
Boolean.toString(conf.isEnableSwagger())))
.map(String::trim)
.orElse(Boolean.toString(conf.isEnableSwagger()))));
@@ -112,35 +112,38 @@ public class IoTDBRestServiceDescriptor {
conf.setEnableHttps(
Boolean.parseBoolean(
Optional.ofNullable(
- properties.getProperty("enable_https",
Boolean.toString(conf.isEnableHttps())))
+ trimProperties.getProperty(
+ "enable_https",
Boolean.toString(conf.isEnableHttps())))
.map(String::trim)
.orElse(Boolean.toString(conf.isEnableHttps()))));
conf.setClientAuth(
Boolean.parseBoolean(
Optional.ofNullable(
- properties.getProperty("client_auth",
Boolean.toString(conf.isClientAuth())))
+ trimProperties.getProperty(
+ "client_auth", Boolean.toString(conf.isClientAuth())))
.map(String::trim)
.orElse(Boolean.toString(conf.isClientAuth()))));
conf.setKeyStorePath(
- Optional.ofNullable(properties.getProperty("key_store_path",
conf.getKeyStorePath()))
+ Optional.ofNullable(trimProperties.getProperty("key_store_path",
conf.getKeyStorePath()))
.map(String::trim)
.orElse(conf.getKeyStorePath()));
conf.setKeyStorePwd(
- Optional.ofNullable(properties.getProperty("key_store_pwd",
conf.getKeyStorePwd()))
+ Optional.ofNullable(trimProperties.getProperty("key_store_pwd",
conf.getKeyStorePwd()))
.map(String::trim)
.orElse(conf.getKeyStorePwd()));
conf.setTrustStorePath(
- Optional.ofNullable(properties.getProperty("trust_store_path",
conf.getTrustStorePath()))
+ Optional.ofNullable(
+ trimProperties.getProperty("trust_store_path",
conf.getTrustStorePath()))
.map(String::trim)
.orElse(conf.getTrustStorePath()));
conf.setTrustStorePwd(
- Optional.ofNullable(properties.getProperty("trust_store_pwd",
conf.getTrustStorePwd()))
+ Optional.ofNullable(trimProperties.getProperty("trust_store_pwd",
conf.getTrustStorePwd()))
.map(String::trim)
.orElse(conf.getTrustStorePwd()));
conf.setIdleTimeoutInSeconds(
Integer.parseInt(
Optional.ofNullable(
- properties.getProperty(
+ trimProperties.getProperty(
"idle_timeout_in_seconds",
Integer.toString(conf.getIdleTimeoutInSeconds())))
.map(String::trim)
@@ -148,7 +151,7 @@ public class IoTDBRestServiceDescriptor {
conf.setCacheExpireInSeconds(
Integer.parseInt(
Optional.ofNullable(
- properties.getProperty(
+ trimProperties.getProperty(
"cache_expire_in_seconds",
Integer.toString(conf.getCacheExpireInSeconds())))
.map(String::trim)
@@ -156,14 +159,14 @@ public class IoTDBRestServiceDescriptor {
conf.setCacheInitNum(
Integer.parseInt(
Optional.ofNullable(
- properties.getProperty(
+ trimProperties.getProperty(
"cache_init_num",
Integer.toString(conf.getCacheInitNum())))
.map(String::trim)
.orElse(Integer.toString(conf.getCacheInitNum()))));
conf.setCacheMaxNum(
Integer.parseInt(
Optional.ofNullable(
- properties.getProperty(
+ trimProperties.getProperty(
"cache_max_num",
Integer.toString(conf.getCacheMaxNum())))
.map(String::trim)
.orElse(Integer.toString(conf.getCacheMaxNum()))));
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/StorageEngine.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/StorageEngine.java
index db050b3e6ed..87679e32a8d 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/StorageEngine.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/StorageEngine.java
@@ -30,6 +30,7 @@ import org.apache.iotdb.commons.conf.CommonConfig;
import org.apache.iotdb.commons.conf.CommonDescriptor;
import org.apache.iotdb.commons.conf.ConfigurationFileUtils;
import org.apache.iotdb.commons.conf.IoTDBConstant;
+import org.apache.iotdb.commons.conf.TrimProperties;
import org.apache.iotdb.commons.consensus.DataRegionId;
import org.apache.iotdb.commons.consensus.index.ProgressIndex;
import org.apache.iotdb.commons.exception.IllegalPathException;
@@ -91,7 +92,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.Properties;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
@@ -656,7 +656,7 @@ public class StorageEngine implements IService {
if (newConfigItems.isEmpty()) {
return tsStatus;
}
- Properties properties = new Properties();
+ TrimProperties properties = new TrimProperties();
properties.putAll(newConfigItems);
URL configFileUrl =
IoTDBDescriptor.getPropsUrl(CommonConfig.SYSTEM_CONFIG_NAME);
diff --git
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/PropertiesTest.java
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/conf/PropertiesTest.java
similarity index 77%
rename from
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/PropertiesTest.java
rename to
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/conf/PropertiesTest.java
index 435f417ab58..49a380acc25 100755
---
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/PropertiesTest.java
+++
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/conf/PropertiesTest.java
@@ -17,10 +17,14 @@
* under the License.
*/
-package org.apache.iotdb.db.utils; // package org.apache.iotdb.db.utils;
+package org.apache.iotdb.db.conf;
-import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.commons.conf.TrimProperties;
+import com.tngtech.archunit.core.domain.JavaClasses;
+import com.tngtech.archunit.core.importer.ClassFileImporter;
+import com.tngtech.archunit.core.importer.ImportOption;
+import com.tngtech.archunit.lang.ArchRule;
import org.apache.tsfile.enums.TSDataType;
import org.apache.tsfile.file.metadata.enums.TSEncoding;
import org.junit.Assert;
@@ -28,11 +32,13 @@ import org.junit.Test;
import java.util.Properties;
+import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
+
public class PropertiesTest {
@Test
public void PropertiesWithSpace() {
IoTDBDescriptor descriptor = IoTDBDescriptor.getInstance();
- Properties properties = new Properties();
+ TrimProperties properties = new TrimProperties();
properties.setProperty("load_active_listening_max_thread_num", "8 "); //
data type: int
properties.setProperty("load_active_listening_enable", "true "); // data
type: Boolean
properties.setProperty("into_operation_buffer_size_in_byte", "104857600
"); // data type: long
@@ -79,4 +85,27 @@ public class PropertiesTest {
Assert.fail(e.getMessage());
}
}
+
+ @Test
+ public void TrimPropertiesOnly() {
+ JavaClasses allClasses =
+ new ClassFileImporter()
+ .withImportOption(new ImportOption.DoNotIncludeTests())
+ .importPackages("org.apache.iotdb");
+
+ ArchRule rule =
+ noClasses()
+ .that()
+ .areAssignableTo("org.apache.iotdb.db.conf.IoTDBDescriptor")
+ .or()
+
.areAssignableTo("org.apache.iotdb.db.conf.rest.IoTDBRestServiceDescriptor")
+ .or()
+ .areAssignableTo("org.apache.iotdb.commons.conf.CommonDescriptor")
+ .should()
+ .callMethod(Properties.class, "getProperty", String.class)
+ .orShould()
+ .callMethod(Properties.class, "getProperty", String.class,
String.class);
+
+ rule.check(allClasses);
+ }
}
diff --git
a/iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/config/MetricConfigDescriptor.java
b/iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/config/MetricConfigDescriptor.java
index f1ec288d47a..11decb83369 100644
---
a/iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/config/MetricConfigDescriptor.java
+++
b/iotdb-core/metrics/interface/src/main/java/org/apache/iotdb/metrics/config/MetricConfigDescriptor.java
@@ -24,6 +24,7 @@ import org.apache.iotdb.metrics.utils.InternalReporterType;
import org.apache.iotdb.metrics.utils.MetricLevel;
import org.apache.iotdb.metrics.utils.ReporterType;
+import java.util.Optional;
import java.util.Properties;
import java.util.stream.Collectors;
@@ -174,7 +175,10 @@ public class MetricConfigDescriptor {
/** Get property from confignode or datanode. */
private String getProperty(
String target, String defaultValue, Properties properties, boolean
isConfigNode) {
- return properties.getProperty((isConfigNode ? "cn_" : "dn_") + target,
defaultValue);
+ return Optional.ofNullable(
+ properties.getProperty((isConfigNode ? "cn_" : "dn_") + target,
defaultValue))
+ .map(String::trim)
+ .orElse(defaultValue);
}
private static class MetricConfigDescriptorHolder {
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonDescriptor.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonDescriptor.java
index 4ba4632afad..26ace0305c2 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonDescriptor.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/CommonDescriptor.java
@@ -27,7 +27,6 @@ import org.apache.iotdb.confignode.rpc.thrift.TGlobalConfig;
import java.io.File;
import java.io.IOException;
import java.util.Optional;
-import java.util.Properties;
public class CommonDescriptor {
@@ -71,7 +70,7 @@ public class CommonDescriptor {
config.setProcedureWalFolder(systemDir + File.separator + "procedure");
}
- public void loadCommonProps(Properties properties) throws IOException {
+ public void loadCommonProps(TrimProperties properties) throws IOException {
config.setAuthorizerProvider(
properties.getProperty("authorizer_provider_class",
config.getAuthorizerProvider()).trim());
// if using org.apache.iotdb.db.auth.authorizer.OpenIdAuthorizer,
openID_url is needed.
@@ -247,7 +246,7 @@ public class CommonDescriptor {
loadRetryProperties(properties);
}
- private void loadPipeProps(Properties properties) {
+ private void loadPipeProps(TrimProperties properties) {
config.setPipeNonForwardingEventsProgressReportInterval(
Integer.parseInt(
properties.getProperty(
@@ -633,7 +632,7 @@ public class CommonDescriptor {
String.valueOf(config.getPipeEventReferenceEliminateIntervalSeconds()))));
}
- private void loadSubscriptionProps(Properties properties) {
+ private void loadSubscriptionProps(TrimProperties properties) {
config.setSubscriptionCacheMemoryUsagePercentage(
Float.parseFloat(
properties.getProperty(
@@ -721,7 +720,7 @@ public class CommonDescriptor {
String.valueOf(config.getSubscriptionMetaSyncerSyncIntervalMinutes()))));
}
- public void loadRetryProperties(Properties properties) throws IOException {
+ public void loadRetryProperties(TrimProperties properties) throws
IOException {
config.setRemoteWriteMaxRetryDurationInMs(
Long.parseLong(
properties.getProperty(
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/TrimProperties.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/TrimProperties.java
new file mode 100644
index 00000000000..aa627367e82
--- /dev/null
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/conf/TrimProperties.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.commons.conf;
+
+import java.util.Optional;
+import java.util.Properties;
+
+public class TrimProperties extends Properties {
+ @Override
+ public synchronized Object get(Object key) {
+ Object value = super.get(key);
+ if (value instanceof String) {
+ return ((String) value).trim();
+ }
+ return value;
+ }
+
+ @Override
+ public synchronized Object put(Object key, Object value) {
+ if (value instanceof String) {
+ value = ((String) value).trim();
+ }
+ return super.put(key, value);
+ }
+
+ @Override
+ public synchronized String getProperty(String key, String defaultValue) {
+ String val = getProperty(key);
+ if (defaultValue != null) {
+ defaultValue = defaultValue.trim();
+ }
+ return Optional.ofNullable(val).map(String::trim).orElse(defaultValue);
+ }
+}