Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public static void setUp() throws Exception {
EnvFactory.getEnv()
.getConfig()
.getCommonConfig()
.setSchemaRegionGroupExtensionPolicy("CUSTOM")
.setDataRegionGroupExtensionPolicy("CUSTOM")
.setDefaultSchemaRegionGroupNumPerDatabase(testDefaultSchemaRegionGroupNumPerDatabase)
.setDefaultDataRegionGroupNumPerDatabase(testDefaultDataRegionGroupNumPerDatabase);

Expand Down Expand Up @@ -132,7 +134,7 @@ public void testRegionGroupNumControlThroughCreation()
final int testDataRegionGroupNum = 3;
String createDatabaseSQL =
String.format(
"CREATE DATABASE %s WITH SCHEMA_REGION_GROUP_NUM=%d, DATA_REGION_GROUP_NUM=%d;",
"CREATE DATABASE %s WITH MAX_SCHEMA_REGION_GROUP_NUM=%d, MAX_DATA_REGION_GROUP_NUM=%d;",
database, testSchemaRegionGroupNum, testDataRegionGroupNum);
statement.execute(createDatabaseSQL);
insertBatchData(statement, database, 0);
Expand Down Expand Up @@ -204,7 +206,7 @@ public void testRegionGroupNumControlThroughAlter()
final int testDataRegionGroupNum = 3;
String alterDatabaseSQL =
String.format(
"ALTER DATABASE %s WITH SCHEMA_REGION_GROUP_NUM=%d, DATA_REGION_GROUP_NUM=%d;",
"ALTER DATABASE %s WITH MAX_SCHEMA_REGION_GROUP_NUM=%d, MAX_DATA_REGION_GROUP_NUM=%d;",
database, testSchemaRegionGroupNum, testDataRegionGroupNum);
statement.execute(alterDatabaseSQL);
insertBatchData(statement, database, batchSize);
Expand Down Expand Up @@ -233,4 +235,16 @@ public void testRegionGroupNumControlThroughAlter()
Assert.assertEquals(testDataRegionGroupNum, dataRegionGroupNum.get());
}
}

@Test
public void testDeprecatedRegionGroupNumSqlRejected() throws SQLException {
try (final Connection connection = EnvFactory.getEnv().getConnection();
final Statement statement = connection.createStatement()) {
Assert.assertThrows(
SQLException.class,
() ->
statement.execute(
"CREATE DATABASE root.paradise3 WITH SCHEMA_REGION_GROUP_NUM=3, DATA_REGION_GROUP_NUM=4;"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,7 @@ public static boolean tryExecuteNonQueriesWithRetry(
}
}
connectionToUse = null;
statement = null;

if (retryCountLeft > 0) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ public void testNoTree() throws Exception {
senderEnv,
Arrays.asList(
"create database root.test",
"alter database root.test with schema_region_group_num=2, data_region_group_num=3",
"create timeSeries root.test.d1.s1 int32",
"insert into root.test.d1 (s1) values (1)"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public void setUp() {
// Limit the schemaRegion number to 1 to guarantee the after sql executed on the same region
// of the tested idempotent sql.
.setDefaultSchemaRegionGroupNumPerDatabase(1)
.setSchemaRegionGroupExtensionPolicy("CUSTOM")
.setDataRegionGroupExtensionPolicy("CUSTOM")
.setConfigNodeConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS)
.setSchemaRegionConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS)
.setEnforceStrongPassword(false)
Expand All @@ -75,6 +77,8 @@ public void setUp() {
.getConfig()
.getCommonConfig()
.setAutoCreateSchemaEnabled(true)
.setSchemaRegionGroupExtensionPolicy("CUSTOM")
.setDataRegionGroupExtensionPolicy("CUSTOM")
.setConfigNodeConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS)
.setSchemaRegionConsensusProtocolClass(ConsensusFactory.RATIS_CONSENSUS)
.setEnforceStrongPassword(false)
Expand Down Expand Up @@ -289,7 +293,7 @@ public void testCreateDatabaseIdempotent() throws Exception {
public void testAlterDatabaseIdempotent() throws Exception {
testIdempotent(
Collections.singletonList("create database root.sg1"),
"ALTER DATABASE root.sg1 WITH SCHEMA_REGION_GROUP_NUM=2, DATA_REGION_GROUP_NUM=3;",
"ALTER DATABASE root.sg1 WITH MAX_SCHEMA_REGION_GROUP_NUM=2, MAX_DATA_REGION_GROUP_NUM=3;",
"create database root.sg2",
"count databases",
"count,",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.iotdb.itbase.category.TableClusterIT;
import org.apache.iotdb.itbase.category.TableLocalStandaloneIT;
import org.apache.iotdb.itbase.env.BaseEnv;
import org.apache.iotdb.jdbc.IoTDBSQLException;

import org.junit.After;
import org.junit.Assert;
Expand Down Expand Up @@ -203,8 +204,7 @@ public void testManageDatabase() {
statement.execute("drop database IF EXISTS test");

// Test create database with properties
statement.execute(
"create database test_prop with (ttl=300, schema_region_group_num=DEFAULT, time_partition_interval=100000)");
statement.execute("create database test_prop with (ttl=300, time_partition_interval=100000)");
databaseNames = new String[] {"test_prop"};
TTLs = new String[] {"300"};
timePartitionInterval = new int[] {100000};
Expand Down Expand Up @@ -811,8 +811,11 @@ public void testMixedDatabase() throws SQLException {
try (final Connection connection = EnvFactory.getEnv().getConnection();
final Statement statement = connection.createStatement()) {
statement.execute("create database root.test");
statement.execute(
"alter database root.test WITH SCHEMA_REGION_GROUP_NUM=2, DATA_REGION_GROUP_NUM=3");
Assert.assertThrows(
IoTDBSQLException.class,
() ->
statement.execute(
"alter database root.test WITH MAX_SCHEMA_REGION_GROUP_NUM=2, MAX_DATA_REGION_GROUP_NUM=3"));
statement.execute("insert into root.test.d1 (s1) values(1)");
statement.execute("drop database root.test");
}
Expand Down Expand Up @@ -882,6 +885,34 @@ public void testCountDatabases() throws SQLException {
}
}

@Test
public void testMaxRegionGroupNumRejectedInAutoPolicy() throws SQLException {
try (final Connection connection =
EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
final Statement statement = connection.createStatement()) {
try {
statement.execute("create database test_max with(max_data_region_group_num=4)");
fail("max_data_region_group_num should be rejected under AUTO policy");
} catch (final SQLException e) {
assertTrue(
e.getMessage()
.contains(
"max_data_region_group_num can only be set when data_region_group_extension_policy is CUSTOM"));
}

statement.execute("create database test_max");
try {
statement.execute("alter database test_max set properties max_data_region_group_num=4");
fail("max_data_region_group_num should be rejected under AUTO policy");
} catch (final SQLException e) {
assertTrue(
e.getMessage()
.contains(
"max_data_region_group_num can only be set when data_region_group_extension_policy is CUSTOM"));
}
}
}

@Test
public void testDBAuth() throws SQLException {
try (final Connection adminCon = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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.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.category.TableLocalStandaloneIT;
import org.apache.iotdb.itbase.env.BaseEnv;

import org.junit.After;
import org.junit.Assert;
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.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collections;

@RunWith(IoTDBTestRunner.class)
@Category({TableLocalStandaloneIT.class, TableClusterIT.class})
public class IoTDBDatabaseMaxRegionGroupNumIT {

@Before
public void setUp() throws Exception {
EnvFactory.getEnv()
.getConfig()
.getCommonConfig()
.setSchemaRegionGroupExtensionPolicy("CUSTOM")
.setDataRegionGroupExtensionPolicy("CUSTOM")
.setDefaultSchemaRegionGroupNumPerDatabase(1)
.setDefaultDataRegionGroupNumPerDatabase(2);
EnvFactory.getEnv().initClusterEnvironment();
}

@After
public void tearDown() throws Exception {
EnvFactory.getEnv().cleanClusterEnvironment();
}

@Test
public void testCreateAndAlterMaxRegionGroupNum() throws SQLException {
try (final Connection connection =
EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
final Statement statement = connection.createStatement()) {
statement.execute(
"create database test_create with(max_schema_region_group_num=3, max_data_region_group_num=4)");
TestUtils.assertResultSetEqual(
statement.executeQuery(
"select database, max_schema_region_group_num, max_data_region_group_num "
+ "from information_schema.databases where database = 'test_create'"),
"database,max_schema_region_group_num,max_data_region_group_num,",
Collections.singleton("test_create,3,4,"));

statement.execute("create database test_alter");
statement.execute(
"alter database test_alter set properties max_schema_region_group_num=3, max_data_region_group_num=4");
try (final ResultSet resultSet = statement.executeQuery("show databases details")) {
boolean found = false;
while (resultSet.next()) {
if (!"test_alter".equals(resultSet.getString("Database"))) {
continue;
}
found = true;
org.junit.Assert.assertEquals(3, resultSet.getInt("MaxSchemaRegionGroupNum"));
org.junit.Assert.assertEquals(4, resultSet.getInt("MaxDataRegionGroupNum"));
}
org.junit.Assert.assertTrue(found);
}

Assert.assertThrows(
SQLException.class,
() ->
statement.execute(
"create database test_deprecated with(schema_region_group_num=4, data_region_group_num=5)"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* 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.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.category.TableLocalStandaloneIT;
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({TableLocalStandaloneIT.class, TableClusterIT.class})
public class IoTDBDatabaseMixedRegionGroupPolicyIT {

@Before
public void setUp() throws Exception {
EnvFactory.getEnv()
.getConfig()
.getCommonConfig()
.setSchemaRegionGroupExtensionPolicy("CUSTOM")
.setDataRegionGroupExtensionPolicy("AUTO")
.setDefaultSchemaRegionGroupNumPerDatabase(1)
.setDefaultDataRegionGroupNumPerDatabase(1)
.setDataRegionPerDataNode(4);
EnvFactory.getEnv().initClusterEnvironment();
}

@After
public void tearDown() throws Exception {
EnvFactory.getEnv().cleanClusterEnvironment();
}

@Test
public void testAutoPolicyStillAdjustsWhenTheOtherPolicyIsCustom() throws SQLException {
try (final Connection connection =
EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
final Statement statement = connection.createStatement()) {
statement.execute("create database test_mixed 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_mixed'"),
"database,max_schema_region_group_num,max_data_region_group_num,",
Collections.singleton("test_mixed,2,4,"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ keyWords
| CURRENT_USER
| DATA
| DATA_REPLICATION_FACTOR
| DATA_REGION_GROUP_NUM
| MAX_DATA_REGION_GROUP_NUM
| DATABASE
| DATABASES
| DATANODE
Expand Down Expand Up @@ -215,7 +215,7 @@ keyWords
| RUNNING
| SCHEMA
| SCHEMA_REPLICATION_FACTOR
| SCHEMA_REGION_GROUP_NUM
| MAX_SCHEMA_REGION_GROUP_NUM
| SECURITY
| SELECT
| SERIESSLOTID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ databaseAttributeClause
databaseAttributeKey
: TTL
| TIME_PARTITION_INTERVAL
| SCHEMA_REGION_GROUP_NUM
| DATA_REGION_GROUP_NUM
| MAX_SCHEMA_REGION_GROUP_NUM
| MAX_DATA_REGION_GROUP_NUM
;

// ---- Drop Database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1227,12 +1227,12 @@ TIME_PARTITION_INTERVAL
: T I M E '_' P A R T I T I O N '_' I N T E R V A L
;

SCHEMA_REGION_GROUP_NUM
: S C H E M A '_' R E G I O N '_' G R O U P '_' N U M
MAX_SCHEMA_REGION_GROUP_NUM
: M A X '_' S C H E M A '_' R E G I O N '_' G R O U P '_' N U M
;

DATA_REGION_GROUP_NUM
: D A T A '_' R E G I O N '_' G R O U P '_' N U M
MAX_DATA_REGION_GROUP_NUM
: M A X '_' D A T A '_' R E G I O N '_' G R O U P '_' N U M
;

CURRENT_TIMESTAMP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,14 +625,14 @@ private TSStatus customExtendRegionGroupIfNecessary(

for (final Map.Entry<String, Integer> entry : unassignedPartitionSlotsCountMap.entrySet()) {
final String database = entry.getKey();
final int minRegionGroupNum =
getClusterSchemaManager().getMinRegionGroupNum(database, consensusGroupType);
final int maxRegionGroupNum =
getClusterSchemaManager().getMaxRegionGroupNum(database, consensusGroupType);
final int allocatedRegionGroupCount =
partitionInfo.getRegionGroupCount(database, consensusGroupType);

// Extend RegionGroups until allocatedRegionGroupCount == minRegionGroupNum
if (allocatedRegionGroupCount < minRegionGroupNum) {
allotmentMap.put(database, minRegionGroupNum - allocatedRegionGroupCount);
// Extend RegionGroups until allocatedRegionGroupCount == maxRegionGroupNum
if (allocatedRegionGroupCount < maxRegionGroupNum) {
allotmentMap.put(database, maxRegionGroupNum - allocatedRegionGroupCount);
}
}

Expand Down
Loading