Skip to content

Avoid duplicate DataNode memory configuration initialization - #18467

Open
jt2594838 wants to merge 2 commits into
apache:masterfrom
jt2594838:fix_double_load_mem_config
Open

Avoid duplicate DataNode memory configuration initialization#18467
jt2594838 wants to merge 2 commits into
apache:masterfrom
jt2594838:fix_double_load_mem_config

Conversation

@jt2594838

Copy link
Copy Markdown
Contributor

Description

Problem

IoTDBDescriptor initialized the DataNode memory configuration while loading iotdb-system.properties, then initialized it again with default properties whenever no external properties loader was present. The second initialization could discard configuration-derived memory settings.

Changes

  • Make loadProps report whether the system configuration source was loaded.
  • Initialize memoryConfig with defaults only when neither the system configuration nor an external properties loader initialized it.

Validation

  • mvn test -pl iotdb-core/datanode '-Dtest=IoTDBDescriptorTest,DataNodeMemoryConfigTest' -DfailIfNoTests=false
  • 11 tests passed; Checkstyle and Spotless passed.

This PR has:

  • been self-reviewed.
  • added comments explaining the why and the intent of the code wherever it would not be obvious for an unfamiliar reader.

Key changed/added classes (or packages if there are too many classes) in this PR
  • org.apache.iotdb.db.conf.IoTDBDescriptor


protected IoTDBDescriptor() {
loadProps();
boolean hasLoadedProperties = loadProps();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capture whether the system properties source was loaded because loadProperties initializes memoryConfig as part of that path. The constructor needs this state to distinguish an already configured memory manager from the no-configuration fallback.

/** load a property file and set TsfileDBConfig variables. */
@SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning
private void loadProps() {
private boolean loadProps() {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return a boolean from loadProps so callers can tell whether this method reached the configuration-loading path. The true and false returns mirror the existing URL-present and URL-absent branches without changing their error handling.

// 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) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Require both configuration sources to be absent before applying defaults. This preserves values loaded from iotdb-system.properties while retaining the existing fallback when neither the system file nor an external loader is available.

@jt2594838 jt2594838 changed the title [Core] Avoid duplicate DataNode memory configuration initialization Avoid duplicate DataNode memory configuration initialization Aug 13, 2026
// 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) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a regression test that exercises this constructor branch with a real system configuration source? The 11 tests listed in the PR are unchanged from the parent commit: IoTDBDescriptorTest only checks URL resolution, while DataNodeMemoryConfigTest tests the calculation/default paths directly. As a result, removing && !hasLoadedProperties would still leave all of them passing. A test that initializes a fresh descriptor (ideally in an isolated JVM/classloader) with datanode_memory_proportion=1:1:1:1:1:5, activates the RPC buffer memory control, and verifies a maxMemory / 4 budget instead of the default maxMemory / 20 would cover the reported regression. It would also be useful to retain an assertion for the no-configuration fallback.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out. I added two constructor-level regression tests. One uses a real temporary iotdb-system.properties with datanode_memory_proportion=1:1:1:1:1:5 and verifies the activated RPC buffer budget is maxMemory / 4; the other verifies the no-configuration fallback remains maxMemory / 20. The tests run in separate Surefire forks so the descriptor and memory configuration statics are isolated.

String originalConf = System.getProperty(IoTDBConstant.IOTDB_CONF);
File confDir = temporaryFolder.newFolder();
Files.writeString(
confDir.toPath().resolve(CommonConfig.SYSTEM_CONFIG_NAME),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test uses a real temporary system properties file so the constructor executes the configured-property path. It verifies the regression fix through the public RPC buffer memory control after the descriptor initializes memory from datanode_memory_proportion.


@Test
public void testNoConfigurationSourceInitializesDefaultRpcBufferMemory() {
String originalConf = System.getProperty(IoTDBConstant.IOTDB_CONF);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test keeps the no-configuration fallback covered by forcing the system properties lookup to return no URL. The assertion verifies that the descriptor still installs the default maxMemory / 20 RPC buffer budget when no source initializes memory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants