Skip to content
Merged
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
@@ -0,0 +1,122 @@
/*
* 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.it.database;

import org.apache.iotdb.consensus.ConsensusFactory;
import org.apache.iotdb.it.env.EnvFactory;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.ClusterIT;

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;

@RunWith(IoTDBTestRunner.class)
@Category({ClusterIT.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() {
EnvFactory.getEnv().cleanClusterEnvironment();
}

@Test
public void testMaxDataRegionGroupNumUsesDataReplicationFactor() throws SQLException {
int expectedMaxDataRegionGroupNum =
(int)
Math.ceil((double) DATA_REGION_PER_DATA_NODE * DATA_NODE_NUM / DATA_REPLICATION_FACTOR);

try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
statement.execute("CREATE DATABASE root.data_rf WITH MAX_SCHEMA_REGION_GROUP_NUM=2");

try (ResultSet resultSet = statement.executeQuery("SHOW DATABASES DETAILS root.data_rf")) {
Assert.assertTrue(resultSet.next());
Assert.assertEquals(2, resultSet.getInt("MaxSchemaRegionGroupNum"));
Assert.assertEquals(
expectedMaxDataRegionGroupNum, resultSet.getInt("MaxDataRegionGroupNum"));
Assert.assertFalse(resultSet.next());
}
}
}

@Test
public void testMaxDataRegionGroupNumRejectedUnderAutoPolicy() throws SQLException {
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
SQLException createException =
Assert.assertThrows(
SQLException.class,
() ->
statement.execute(
"CREATE DATABASE root.auto_create WITH MAX_DATA_REGION_GROUP_NUM=4"));
Assert.assertTrue(
createException
.getMessage()
.contains(
"max_data_region_group_num can only be set when "
+ "data_region_group_extension_policy is CUSTOM"));

statement.execute("CREATE DATABASE root.auto_alter");
SQLException alterException =
Assert.assertThrows(
SQLException.class,
() ->
statement.execute(
"ALTER DATABASE root.auto_alter WITH MAX_DATA_REGION_GROUP_NUM=4"));
Assert.assertTrue(
alterException
.getMessage()
.contains(
"max_data_region_group_num can only be set when "
+ "data_region_group_extension_policy is CUSTOM"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* 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.it.database;

import org.apache.iotdb.it.env.EnvFactory;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.ClusterIT;
import org.apache.iotdb.itbase.category.LocalStandaloneIT;

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;

@RunWith(IoTDBTestRunner.class)
@Category({LocalStandaloneIT.class, ClusterIT.class})
public class IoTDBDatabaseMixedRegionGroupPolicyIT {

private static final int DATA_REGION_PER_DATA_NODE = 4;

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

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

@Test
public void testAutoPolicyStillAdjustsWhenTheOtherPolicyIsCustom() throws SQLException {
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
statement.execute("CREATE DATABASE root.mixed WITH MAX_SCHEMA_REGION_GROUP_NUM=2");

try (ResultSet resultSet = statement.executeQuery("SHOW DATABASES DETAILS root.mixed")) {
Assert.assertTrue(resultSet.next());
Assert.assertEquals(2, resultSet.getInt("MaxSchemaRegionGroupNum"));
Assert.assertEquals(DATA_REGION_PER_DATA_NODE, resultSet.getInt("MaxDataRegionGroupNum"));
Assert.assertFalse(resultSet.next());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collections;
Expand All @@ -58,6 +59,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 +135,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 @@ -162,6 +165,53 @@ public void testRegionGroupNumControlThroughCreation()
}
}

@Test
public void testRecreateWithPartialMaxRegionGroupNumUsesDefaultCounterpart() throws SQLException {
try (final Connection connection = EnvFactory.getEnv().getConnection();
final Statement statement = connection.createStatement()) {
final String database = "root.rg_tree_create_schema";
statement.execute(String.format("CREATE DATABASE %s;", database));

try (final ResultSet resultSet =
statement.executeQuery("SHOW DATABASES DETAILS " + database)) {
Assert.assertTrue(resultSet.next());
Assert.assertEquals(
testDefaultSchemaRegionGroupNumPerDatabase,
resultSet.getInt("MaxSchemaRegionGroupNum"));
Assert.assertEquals(
testDefaultDataRegionGroupNumPerDatabase, resultSet.getInt("MaxDataRegionGroupNum"));
Assert.assertFalse(resultSet.next());
}

statement.execute(String.format("DROP DATABASE %s;", database));
statement.execute(
String.format("CREATE DATABASE %s WITH MAX_SCHEMA_REGION_GROUP_NUM=3;", database));

try (final ResultSet resultSet =
statement.executeQuery("SHOW DATABASES DETAILS " + database)) {
Assert.assertTrue(resultSet.next());
Assert.assertEquals(3, resultSet.getInt("MaxSchemaRegionGroupNum"));
Assert.assertEquals(
testDefaultDataRegionGroupNumPerDatabase, resultSet.getInt("MaxDataRegionGroupNum"));
Assert.assertFalse(resultSet.next());
}

final String dataDatabase = "root.rg_tree_create_data";
statement.execute(
String.format("CREATE DATABASE %s WITH MAX_DATA_REGION_GROUP_NUM=4;", dataDatabase));

try (final ResultSet resultSet =
statement.executeQuery("SHOW DATABASES DETAILS " + dataDatabase)) {
Assert.assertTrue(resultSet.next());
Assert.assertEquals(
testDefaultSchemaRegionGroupNumPerDatabase,
resultSet.getInt("MaxSchemaRegionGroupNum"));
Assert.assertEquals(4, resultSet.getInt("MaxDataRegionGroupNum"));
Assert.assertFalse(resultSet.next());
}
}
}

@Test
public void testRegionGroupNumControlThroughAlter()
throws SQLException, ClientManagerException, IOException, InterruptedException, TException {
Expand Down Expand Up @@ -204,7 +254,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 +283,85 @@ public void testRegionGroupNumControlThroughAlter()
Assert.assertEquals(testDataRegionGroupNum, dataRegionGroupNum.get());
}
}

@Test
public void testAlterMaxDataRegionGroupNumCannotDecrease() throws SQLException {
try (final Connection connection = EnvFactory.getEnv().getConnection();
final Statement statement = connection.createStatement()) {
final String database = "root.rg_tree_decrease";
statement.execute(
String.format("CREATE DATABASE %s WITH MAX_DATA_REGION_GROUP_NUM=8;", database));
statement.execute(
String.format("ALTER DATABASE %s WITH MAX_DATA_REGION_GROUP_NUM=16;", database));

final SQLException exception =
Assert.assertThrows(
SQLException.class,
() ->
statement.execute(
String.format(
"ALTER DATABASE %s WITH MAX_DATA_REGION_GROUP_NUM=12;", database)));
Assert.assertTrue(
exception.getMessage(),
exception
.getMessage()
.contains(
"MaxDataRegionGroupNum should be greater than or equal to current max "
+ "DataRegionGroupNum: 16."));

try (final ResultSet resultSet =
statement.executeQuery("SHOW DATABASES DETAILS " + database)) {
Assert.assertTrue(resultSet.next());
Assert.assertEquals(16, resultSet.getInt("MaxDataRegionGroupNum"));
Assert.assertFalse(resultSet.next());
}
}
}

@Test
public void testAlterMaxSchemaRegionGroupNumCannotDecrease() throws SQLException {
try (final Connection connection = EnvFactory.getEnv().getConnection();
final Statement statement = connection.createStatement()) {
final String schemaDatabase = "root.rg_tree_decrease_schema";
statement.execute(
String.format("CREATE DATABASE %s WITH MAX_SCHEMA_REGION_GROUP_NUM=4;", schemaDatabase));
statement.execute(
String.format("ALTER DATABASE %s WITH MAX_SCHEMA_REGION_GROUP_NUM=5;", schemaDatabase));

final SQLException schemaException =
Assert.assertThrows(
SQLException.class,
() ->
statement.execute(
String.format(
"ALTER DATABASE %s WITH MAX_SCHEMA_REGION_GROUP_NUM=3;",
schemaDatabase)));
Assert.assertTrue(
schemaException.getMessage(),
schemaException
.getMessage()
.contains(
"MaxSchemaRegionGroupNum should be greater than or equal to current max "
+ "SchemaRegionGroupNum: 5."));

try (final ResultSet resultSet =
statement.executeQuery("SHOW DATABASES DETAILS " + schemaDatabase)) {
Assert.assertTrue(resultSet.next());
Assert.assertEquals(5, resultSet.getInt("MaxSchemaRegionGroupNum"));
Assert.assertFalse(resultSet.next());
}
}
}

@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;"));
}
}
}
Loading
Loading