From 2958f7c36c4b4f582adc30abe610226e03a6dc5f Mon Sep 17 00:00:00 2001 From: libo Date: Tue, 21 Jul 2026 12:58:05 +0800 Subject: [PATCH] Fix max data region group quota calculation --- ...TDBDatabaseAutoDataRegionGroupQuotaIT.java | 91 +++++++++++++++++++ .../manager/schema/ClusterSchemaManager.java | 4 +- 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDatabaseAutoDataRegionGroupQuotaIT.java diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDatabaseAutoDataRegionGroupQuotaIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDatabaseAutoDataRegionGroupQuotaIT.java new file mode 100644 index 0000000000000..4d2fd8c780c0d --- /dev/null +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDatabaseAutoDataRegionGroupQuotaIT.java @@ -0,0 +1,91 @@ +/* + * 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.relational.it.schema; + +import org.apache.iotdb.consensus.ConsensusFactory; +import org.apache.iotdb.db.it.utils.TestUtils; +import org.apache.iotdb.it.env.EnvFactory; +import org.apache.iotdb.it.framework.IoTDBTestRunner; +import org.apache.iotdb.itbase.category.TableClusterIT; +import org.apache.iotdb.itbase.env.BaseEnv; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Collections; + +@RunWith(IoTDBTestRunner.class) +@Category({TableClusterIT.class}) +public class IoTDBDatabaseAutoDataRegionGroupQuotaIT { + + private static final int CONFIG_NODE_NUM = 1; + private static final int DATA_NODE_NUM = 3; + private static final int SCHEMA_REPLICATION_FACTOR = 3; + private static final int DATA_REPLICATION_FACTOR = 1; + private static final int DATA_REGION_PER_DATA_NODE = 2; + + @Before + public void setUp() throws Exception { + EnvFactory.getEnv() + .getConfig() + .getCommonConfig() + .setSchemaRegionGroupExtensionPolicy("CUSTOM") + .setDataRegionGroupExtensionPolicy("AUTO") + .setSchemaRegionConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS) + .setDefaultSchemaRegionGroupNumPerDatabase(1) + .setDefaultDataRegionGroupNumPerDatabase(1) + .setSchemaReplicationFactor(SCHEMA_REPLICATION_FACTOR) + .setDataReplicationFactor(DATA_REPLICATION_FACTOR) + .setDataRegionPerDataNode(DATA_REGION_PER_DATA_NODE); + EnvFactory.getEnv().initClusterEnvironment(CONFIG_NODE_NUM, DATA_NODE_NUM); + } + + @After + public void tearDown() throws Exception { + EnvFactory.getEnv().cleanClusterEnvironment(); + } + + @Test + public void testMaxDataRegionGroupNumUsesDataReplicationFactor() throws SQLException { + try (final Connection connection = + EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); + final Statement statement = connection.createStatement()) { + final int expectedMaxDataRegionGroupNum = + (int) + Math.ceil( + (double) DATA_REGION_PER_DATA_NODE * DATA_NODE_NUM / DATA_REPLICATION_FACTOR); + + statement.execute("create database test_data_region_rf with(max_schema_region_group_num=2)"); + + TestUtils.assertResultSetEqual( + statement.executeQuery( + "select database, max_schema_region_group_num, max_data_region_group_num " + + "from information_schema.databases where database = 'test_data_region_rf'"), + "database,max_schema_region_group_num,max_data_region_group_num,", + Collections.singleton("test_data_region_rf,2," + expectedMaxDataRegionGroupNum + ",")); + } + } +} diff --git a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/schema/ClusterSchemaManager.java b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/schema/ClusterSchemaManager.java index a66b88f0a10c4..357c14eca4aa0 100644 --- a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/schema/ClusterSchemaManager.java +++ b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/schema/ClusterSchemaManager.java @@ -603,7 +603,9 @@ public int adjustRegionGroupNum( ? dataNodeNum : (CONF.getDataRegionPerDataNode() == 0 ? totalCpuCoreNum : dataNodeNum), databaseNum, - databaseSchema.getSchemaReplicationFactor(), + (consensusGroupType == TConsensusGroupType.SchemaRegion) + ? databaseSchema.getSchemaReplicationFactor() + : databaseSchema.getDataReplicationFactor(), allocatedRegionGroupCount); LOGGER.info( (consensusGroupType == TConsensusGroupType.SchemaRegion)