From 6e3e5b0ac085242ae3232490e340ee2d7448d065 Mon Sep 17 00:00:00 2001 From: Tian Jiang Date: Thu, 13 Aug 2026 16:26:56 +0800 Subject: [PATCH 1/2] fix double load mem config --- .../java/org/apache/iotdb/db/conf/IoTDBDescriptor.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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 15d2b7d003d5f..711a82038b516 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 @@ -141,7 +141,7 @@ public class IoTDBDescriptor { } protected IoTDBDescriptor() { - loadProps(); + boolean hasLoadedProperties = loadProps(); ServiceLoader propertiesLoaderServiceLoader = ServiceLoader.load(IPropertiesLoader.class); boolean hasProperties = false; @@ -167,8 +167,8 @@ protected IoTDBDescriptor() { .getConfig() .setCustomizedProperties(loader.getCustomizedProperties()); } - // if there are no properties, we need to init memory config - if (!hasProperties) { + // If no configuration source initialized the memory config, initialize it with defaults. + if (!hasLoadedProperties && !hasProperties) { memoryConfig.init(new TrimProperties()); } } @@ -227,7 +227,7 @@ else if (!urlString.endsWith(".properties")) { /** load a property file and set TsfileDBConfig variables. */ @SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning - private void loadProps() { + private boolean loadProps() { TrimProperties commonProperties = new TrimProperties(); // if new properties file exist, skip old properties files URL url = getPropsUrl(CommonConfig.SYSTEM_CONFIG_NAME); @@ -256,11 +256,13 @@ private void loadProps() { .getMetricConfig() .updateRpcInstance(NodeType.DATANODE, SchemaConstant.SYSTEM_DATABASE); } + return true; } else { LOGGER.warn( DataNodeMiscMessages .MISC_LOG_COULDN_T_LOAD_THE_CONFIGURATION_FROM_ANY_OF_THE_KNOWN_SOURCES_EE3ED103, CommonConfig.SYSTEM_CONFIG_NAME); + return false; } } From a388f76257d8a092e87572a87fbd9388e328a56a Mon Sep 17 00:00:00 2001 From: Tian Jiang Date: Mon, 24 Aug 2026 12:23:00 +0800 Subject: [PATCH 2/2] test: cover DataNode memory config initialization --- ...oTDBDescriptorDefaultMemoryConfigTest.java | 52 +++++++++++++++ .../IoTDBDescriptorSystemPropertiesTest.java | 65 +++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 iotdb-core/datanode/src/test/java/org/apache/iotdb/db/conf/IoTDBDescriptorDefaultMemoryConfigTest.java create mode 100644 iotdb-core/datanode/src/test/java/org/apache/iotdb/db/conf/IoTDBDescriptorSystemPropertiesTest.java diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/conf/IoTDBDescriptorDefaultMemoryConfigTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/conf/IoTDBDescriptorDefaultMemoryConfigTest.java new file mode 100644 index 0000000000000..3bf390b096253 --- /dev/null +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/conf/IoTDBDescriptorDefaultMemoryConfigTest.java @@ -0,0 +1,52 @@ +/* + * 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.db.conf; + +import org.apache.iotdb.commons.conf.IoTDBConstant; +import org.apache.iotdb.commons.memory.MemoryConfig; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class IoTDBDescriptorDefaultMemoryConfigTest { + + @Test + public void testNoConfigurationSourceInitializesDefaultRpcBufferMemory() { + String originalConf = System.getProperty(IoTDBConstant.IOTDB_CONF); + // An unsupported classpath URL makes getPropsUrl return null without opening a file. + System.setProperty(IoTDBConstant.IOTDB_CONF, "classpath:/missing-iotdb-system.properties"); + + try { + // The descriptor and MemoryConfig statics are isolated by surefire's per-class fork. + IoTDBDescriptor descriptor = new IoTDBDescriptor(); + descriptor.getMemoryConfig().activateAutoResizingBufferMemoryControl(); + + assertEquals( + Runtime.getRuntime().maxMemory() / 20, + MemoryConfig.getInstance().getAutoResizingBufferMemoryTotalSizeInBytes()); + } finally { + if (originalConf == null) { + System.clearProperty(IoTDBConstant.IOTDB_CONF); + } else { + System.setProperty(IoTDBConstant.IOTDB_CONF, originalConf); + } + } + } +} diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/conf/IoTDBDescriptorSystemPropertiesTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/conf/IoTDBDescriptorSystemPropertiesTest.java new file mode 100644 index 0000000000000..43d2fe3002197 --- /dev/null +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/conf/IoTDBDescriptorSystemPropertiesTest.java @@ -0,0 +1,65 @@ +/* + * 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.db.conf; + +import org.apache.iotdb.commons.conf.CommonConfig; +import org.apache.iotdb.commons.conf.IoTDBConstant; +import org.apache.iotdb.commons.memory.MemoryConfig; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; + +import static org.junit.Assert.assertEquals; + +public class IoTDBDescriptorSystemPropertiesTest { + + @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); + + @Test + public void testSystemPropertiesInitializeConfiguredRpcBufferMemory() throws Exception { + String originalConf = System.getProperty(IoTDBConstant.IOTDB_CONF); + File confDir = temporaryFolder.newFolder(); + Files.writeString( + confDir.toPath().resolve(CommonConfig.SYSTEM_CONFIG_NAME), + "datanode_memory_proportion=1:1:1:1:1:5\n", + StandardCharsets.UTF_8); + System.setProperty(IoTDBConstant.IOTDB_CONF, confDir.getAbsolutePath()); + + try { + // The descriptor and MemoryConfig statics are isolated by surefire's per-class fork. + IoTDBDescriptor descriptor = new IoTDBDescriptor(); + descriptor.getMemoryConfig().activateAutoResizingBufferMemoryControl(); + + assertEquals( + Runtime.getRuntime().maxMemory() / 4, + MemoryConfig.getInstance().getAutoResizingBufferMemoryTotalSizeInBytes()); + } finally { + if (originalConf == null) { + System.clearProperty(IoTDBConstant.IOTDB_CONF); + } else { + System.setProperty(IoTDBConstant.IOTDB_CONF, originalConf); + } + } + } +}