This is an automated email from the ASF dual-hosted git repository. jiangtian pushed a commit to branch fix_set_default_sg_level_13 in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit b0ef9d262e593b6d6658fda417258e5ae8ed02dc Author: Tian Jiang <[email protected]> AuthorDate: Wed Dec 18 12:06:59 2024 +0800 Fix setting illegal default_storage_group_level does not report an error (cherry picked from commit 391d153759086ff947e238b196021e71aafbce1b) --- .../iotdb/db/it/IoTDBSetConfigurationIT.java | 35 ++++++++++++++++++++++ .../java/org/apache/iotdb/db/conf/IoTDBConfig.java | 5 ++++ .../exception/sql/StatementAnalyzeException.java | 4 +++ .../analyze/cache/partition/PartitionCache.java | 2 +- .../schemaengine/schemaregion/utils/MetaUtils.java | 9 ++++-- .../conf/iotdb-system.properties.template | 4 +++ 6 files changed, 56 insertions(+), 3 deletions(-) diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSetConfigurationIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSetConfigurationIT.java index da6db7a12a8..289dc895f88 100644 --- a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSetConfigurationIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSetConfigurationIT.java @@ -39,11 +39,16 @@ import java.io.IOException; import java.nio.file.Files; import java.sql.Connection; import java.sql.ResultSet; +import java.sql.SQLException; import java.sql.Statement; import java.util.Arrays; import java.util.Properties; import java.util.concurrent.TimeUnit; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + @RunWith(IoTDBTestRunner.class) @Category({LocalStandaloneIT.class}) public class IoTDBSetConfigurationIT { @@ -202,4 +207,34 @@ public class IoTDBSetConfigurationIT { + CommonConfig.SYSTEM_CONFIG_NAME; return new File(systemPropertiesPath); } + + @Test + public void testSetDefaultSGLevel() throws SQLException { + try (Connection connection = EnvFactory.getEnv().getConnection(); + Statement statement = connection.createStatement()) { + // legal value + statement.execute("set configuration \"default_storage_group_level\"=\"3\""); + statement.execute("INSERT INTO root.a.b.c.d1(timestamp, s1) VALUES (1, 1)"); + ResultSet databases = statement.executeQuery("show databases"); + databases.next(); + Assert.assertEquals("root.a.b.c", databases.getString(1)); + assertFalse(databases.next()); + + // path too short + try { + statement.execute("INSERT INTO root.fail(timestamp, s1) VALUES (1, 1)"); + } catch (SQLException e) { + assertEquals( + "509: root.fail is not a legal path, because it is no longer than default sg level: 3", + e.getMessage()); + } + + // illegal value + try { + statement.execute("set configuration \"default_storage_group_level\"=\"-1\""); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("Illegal defaultStorageGroupLevel: -1, should >= 1")); + } + } + } } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java index 577bfa25e12..738833bc515 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java @@ -2434,6 +2434,11 @@ public class IoTDBConfig { } void setDefaultStorageGroupLevel(int defaultStorageGroupLevel) { + if (defaultStorageGroupLevel < 1) { + throw new IllegalArgumentException( + String.format( + "Illegal defaultStorageGroupLevel: %d, should >= 1", defaultStorageGroupLevel)); + } this.defaultStorageGroupLevel = defaultStorageGroupLevel; } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/exception/sql/StatementAnalyzeException.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/exception/sql/StatementAnalyzeException.java index 3ca1e397c37..219d73b1b7c 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/exception/sql/StatementAnalyzeException.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/exception/sql/StatementAnalyzeException.java @@ -28,4 +28,8 @@ public class StatementAnalyzeException extends RuntimeException { public StatementAnalyzeException(Exception cause) { super(cause); } + + public StatementAnalyzeException(String message, Throwable cause) { + super(message, cause); + } } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/partition/PartitionCache.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/partition/PartitionCache.java index 56934931b8c..91785849e76 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/partition/PartitionCache.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/partition/PartitionCache.java @@ -384,7 +384,7 @@ public class PartitionCache { } } catch (TException | MetadataException | ClientManagerException e) { throw new StatementAnalyzeException( - "An error occurred when executing getDeviceToStorageGroup():" + e.getMessage()); + "An error occurred when executing getDeviceToDatabase():" + e.getMessage(), e); } } } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/utils/MetaUtils.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/utils/MetaUtils.java index 67fbb6550d7..108b5f14d9d 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/utils/MetaUtils.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/utils/MetaUtils.java @@ -61,8 +61,13 @@ public class MetaUtils { public static PartialPath getStorageGroupPathByLevel(PartialPath path, int level) throws MetadataException { String[] nodeNames = path.getNodes(); - if (nodeNames.length <= level || !nodeNames[0].equals(IoTDBConstant.PATH_ROOT)) { - throw new IllegalPathException(path.getFullPath()); + if (nodeNames.length <= level) { + throw new IllegalPathException( + path.getFullPath(), "it is no longer than default sg level: " + level); + } + if (!nodeNames[0].equals(IoTDBConstant.PATH_ROOT)) { + throw new IllegalPathException( + path.getFullPath(), "it does not start with " + IoTDBConstant.PATH_ROOT); } String[] storageGroupNodes = new String[level + 1]; System.arraycopy(nodeNames, 0, storageGroupNodes, 0, level + 1); diff --git a/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template b/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template index d6ca096864f..0865aa511a2 100644 --- a/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template +++ b/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template @@ -850,8 +850,12 @@ enable_auto_create_schema=true # Database level when creating schema automatically is enabled # e.g. root.sg0.d1.s2 # we will set root.sg0 as the database if database level is 1 +# If the incoming path is shorter than this value, the creation/insertion will fail. # effectiveMode: hot_reload # Datatype: int +# Range: [1, Integer.MAX_VALUE] +# Default: 1 +# When illegal: report an error and change nothing default_storage_group_level=1 # ALL data types: BOOLEAN, INT32, INT64, FLOAT, DOUBLE, TEXT
